Adding an environment variable to Bash PATH in OS X

I can never remember how to add environment variables to .bash_profile. This post just reminds me how to do that.

It’s dead simple. Just open up Terminal and enter the following (changing the path ‘/opt/subversion/bin’, naturally):

echo 'export PATH=/opt/subversion/bin:$PATH' >> ~/.bash_profile

If .bash_profile doesn’t exist yet (and it doesn’t by default), it’ll be created. Otherwise, the environment variable will be added to that file.

Credit to Indy Nagpal.

2 thoughts on “Adding an environment variable to Bash PATH in OS X

  1. Hi Peter,

    I have added it to the first line in my ~/.profile file this way:
    and it works just the same. I wonder if the shell looks for them both once you open Terminal.


    1. If I’m not mistaken, the following startup files will be searched for in order. Whichever one is found first will be used by the shell:


      So yeah, .profile should work, as long as you don’t also have a .bash_profile.

Leave a Reply