So I've been trying to do a cleanup of sorts on my mac OS .bash_profile (had a few issues with it), and now when I do echo $PATH on my Terminal I get the following:

/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home :/usr/local/sbin :/usr/local/sbin :/usr/local/sbin :/usr/local/bin :/usr/bin :/bin :/usr/sbin :/sbin :/Users/herrmartell/bin :/usr/local/bin/mysql/bin :/Users/herrmartell/bin :/usr/local/bin/mysql/bin :/Users/herrmartell/bin :/usr/local/bin/mysql/bin

As you can see that's quite the number of duplicated entries. Which is odd, because this is what my .bash_profile looks like:

export PATH=$PATH:$HOME/bin export PATH="/usr/local/sbin:$PATH" export MYSQL_PATH="/usr/local/bin/mysql" export PATH=$PATH:$MYSQL_PATH/bin export JAVA_HOME="/path/is/too/long/sorry" export PATH=${JAVA_HOME}:$PATH

I've tried looking for another .bash_profile/.bash*/.profile file which might be overriding mine, but found none, also the changes I make on this one file are reflected on my echo $PATH results.

Found something related, but it's on Ubuntu and to be honest I got lost: Why do I get duplicated entries in my $PATH?, and then something on Unix (lost me too, sorry): Duplicate entries in $PATH a problem?

So far, it's not giving me problems, but I'd like to avoid actually getting them in the future.

What is wrong on my file then? Thanks.


If you didn't already, try checking the following paths

cat ~/.bashrc
cat ~/.profile
cat ~/.bash_profile
cat /etc/bashrc
cat /etc/profile
cat /etc/bash_profile

You can also try

find ~ -type f -size -30k -exec grep -H herrmartell {} \;
find /etc -type f -size -30k -exec grep -H herrmartell {} \;
| improve this answer | |
  • It looks to me like ~/.bash_profile is being run 3 times, so I'd look through the others and see if they're running it redundantly. – Gordon Davisson Jun 8 '17 at 4:26
  • Tried all of those, I can only see .bash_profile (obviously), /etc/bashrc & /etc/profile. None is interfering with my .bash_profile (as far as I can tell). – herrmartell Jun 15 '17 at 23:58

2020 update: In addition to paths associated with the (much maligned) bash shell, newer versions of MacOS use the zsh as the default shell and may be adding to (in that order):

/etc/zshenv    # Read for every shell
~/.zshenv      # Read for every shell except ones started with -f
/etc/zprofile  # Global config for login shells, read before zshrc
~/.zprofile    # User config for login shells
/etc/zshrc     # Global config for interactive shells
~/.zshrc       # User config for interactive shells
/etc/zlogin    # Global config for login shells, read after zshrc
~/.zlogin      # User config for login shells
~/.zlogout     # User config for login shells, read upon logout
/etc/zlogout   # Global config for login shells, read after user logout file

While previously the bash files were sourced conditionally (with the result that some users couldn't get their paths to be added), now all of these zsh files, if they exist, are sourced (with the results that some users find too many paths are added).

In addition, I have found paths in the following places:

private/etc/paths  # this one was the killer for me!
private/etc/paths.save # probably not sourced
private/etc/paths~save1 # probably not sourced

There are almost certainly more paths in other places, but for me private/etc/paths was the origin of much duplication. If anyone reading this finds more places, please ping me to add them!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.