I'd like to set a specified path to $PATH,

I write it to the top of .bashrc

$ cat ~/.bashrc
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH

and activate it

$ source ~/.bashrc

It works


Nonetheless, when I open a new terminal, it's gone.

$ echo $PATH

As a test, I closed all the terminals and restart fresh

$ echo $PATH

The path /usr/local/opt/coreutils/libexec/gnubin is not there.

I checked my operations:

1. put desired path to the top
2. export it 
3. source to activate it.

What's wrong with my operations?


The Terminal app (as well as iTerm) on macOS (which I believe that you are using) starts a login shell by default. When bash is started as a login shell, it reads your ~/.bash_profile file, but not ~/.bashrc.

You may change the way that your terminal starts the shell in the terminal's preferences, or you may make your ~/.bash_profile source the ~/.bashrc file by adding the following to ~/.bash_profile (probably at the end of the file):

if [[ "$-" == *i* ]] && [ -f ~/.bashrc ]; then
    source ~/.bashrc

This would make the login shell also read the ~/.bashrc file if it is an interactive shell and if ~/.bashrc exists.

As an alternative, you may obviously just add the modification to PATH in ~/.bash_profile instead. I believe macOS does not install a default ~/.bashrc file in users' home directories.


| 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.