Mac OS X Tip: Setting PATH environment variables
I’m still getting to grips with this OS X malarkey, and my latest challenge was how to set the PATH environment variables.
I started out wanting to add some aliases for the mysql and mysqladmin commands as I’ve just decided to have a bit of a play with django. On linux I used to edit my .bashrc file to do this, but the version of bash on Mac OS X (10.5.2) doesn’t seem to support this. Hunting around I realised that I should just add the path to these commands to my PATH environment variable, but again: not quite so simple.
I want these commands to be available to everyone, so it turns out you have to edit a file called paths in /etc:
sudo vi /etc/paths
And that was it. Easy when you know how! Oh, and remember to run vi as root using the sudo command….







July 31st, 2008 05:34
Hey there Mark.
I just read this post, great info. But after digging a little I found out that you can use another method to do what you’re saying. You just have to create a file inside /etc/paths.d ; for instance if I’d like to append the mysql directory to the PATH I would do this:
1) Create the file /etc/paths.d/mysql like this:
sudo touch /etc/paths.d/mysql
2) Edit the file:
sudo vim /etc/paths.d/mysql
3) Put the path inside the file:
/usr/local/mysql/bin
I posted three steps so everyone knows what they’re doing, but you could do it all by just creating the file and filling it with the path needed in PATH.
I think this method works better because it is more ordered at the end and you would have a file for each path you want to create for every program that needs it.
Hope this helps.
Cheers. Felipe.
November 24th, 2008 14:17
On Mac OS X exists a file that has the same role of the ~/.bashrc file on Linux and it’s the ~/.bash_profile file.
February 12th, 2009 19:12
Thank you both! I’m also from unix but could find no dot file in my home dir where I set my path, but looking at the value of PATH, I obviously HAD modified it at least once in the past! Sure enough, I had added something under paths.d, just four months ago, too.
What also drives me crazy is that when I search using spotlight, it ignores everything under /etc. Guess I have to go back to using good old find from / if I really want to find things related to system administration.
March 9th, 2009 11:37
Mark, Thanks so much for sharing this.
After almost 2 days I landed on your blog. I wonder why most of the top results in google are misleading and there is nothing that is easily found on apple developers section either. You saved my day!
May 16th, 2009 06:48
Additional info…
The path value in the file in Felipe’s step 3 above is a clean/plain text path, not the path you’d type in a shell to set the PATH environment variable.
I used this technique for a path that had spaces in one of the folder names and when I had the backslash escapes, it wasn’t working. Removing the backslashes made it work like a charm.
Instead of these:
export PATH=$PATH:/Developer/Applications/PLT\ Scheme\ v4.1.5/bin
/Developer/Applications/PLT\ Scheme\ v4.1.5/bin
Use just this:
/Developer/Applications/PLT Scheme v4.1.5/bin
Regards,
-Russell
July 27th, 2009 16:11
Mark and Felipe,
many thanks! This helped me with an issue of webkit-image, a unix tool used for the JOSM editor of OpenStreetMap!
Cheers,
Werner
December 26th, 2009 17:00
The good thing about using a profile configuration file like .bashrc, is that if you ever migrate your home folder to a new machine/OS X install, all your changes go with you. If you edit things in /etc you are unlikely you retain such changes.
The place to put such changes in OS X 10.4 / 10.5 / 10.6 is in ~/.profile . Specifically, I added the line “export PATH=$PATH:~/bin” (no quotes) to my ~/.profile file in order to allow me to install binaries into ~/bin.
July 3rd, 2010 13:35
Thanks Felipe. There are many different ways to change PATH at startup, but this is the one I like most. (I’m using OS X 10.6.) Just one thing: the path in the file mysql has to end with a newline, otherwise it won’t be added properly to PATH.
Cheers
Luc
September 19th, 2010 15:43
Hey Mark -
You said:
> On linux I used to edit my .bashrc file to do this, but the version of bash on Mac OS X (10.5.2) doesn’t seem to support this
This isn’t exactly true. the .bashrc file is still used for executable shells in OSX, however it’s he .bash_profile that is used in login shells (like the Terminal). You’ll want to edit to add paths, like this:
export PATH=$PATH:/usr/local/mysql/bin
regards