Leopard and Bash Shell environment paths
If you recently made the upgrade to Leopard and you’re a frequent user of the OSX Terminal application, you may find that the environment paths that you had set up for the bash shell no longer work. Previously in Tiger, one can easily define those paths by creating a .bash_profile or .profile configuration file in the user directory, or editing the system-wide configuration file /etc/.profile directly if you have root access.
While I personally have never been able to make the configuration files work in the user directory, I’ve had success setting my environment paths in /etc/.profile. However, along with many other components that got shuffled around in the latest release of OSX, those profile settings are no longer found in the same locations. Oh why o why, Apple?
In Leopard, the road to setting environment paths is a rather convoluted one. I wish Apple had made it easier but to date, I haven’t come across any other simpler solution. Here are the few steps that I took to resolve the issue:
- If you open
/etc/.profilein a text editor, you’d see that the Terminal now loads the environment paths via a configuration file in/usr/libexec/path_helper. - Opening the
path_helperfile reveals that environment paths are now collectively stored in a file aptly namedpathsin theetcdirectory. Open/etc/pathsand you’d see that all the environment paths are neatly listed here. You can simply add your desired paths such as/usr/local/mysql/binto this list. - Relaunch the Terminal and test.
Please note that root user needs to be enabled in order for you to edit the /etc/paths file. To enable the root user, see this article.
Addendum
Good news! Since writing this tutorial I had successfully implemented a .bash_profile file to my shell, effectively rendering the above procedure unnecessary. The secret is in applying the Unix source command which is built into the shell. Create your .bash_profile document at the root of your home directory as follows:
and add any relevant paths that you may need. Then execute source .bash_profile in the command line. This ensures that changes to the environment made in .bash_profile are registered before you restart the shell.
July 30th, 2008 at 6:48 pm
Many thanks, had never figured this out before under Tiger, but your article showed exactly what I needed to do in Leopard.
December 3rd, 2008 at 2:57 pm
Thanks for the tip! Glad this is the second hit on a “osx leopard shell bash path” Google search. It was exactly what I was looking for! ;-)
May 22nd, 2009 at 2:20 pm
Not sure what is causing your issues, but creating ~/.profile works great for me. I have tons of PATH bits in mine.
December 6th, 2009 at 12:14 pm
In addition to editing /etc/paths , you can also create files in the /etc/paths.d/ folder (one foldername per line). path_helper will process each file the same way as it processes /etc/paths. This can make it easier to organize your paths (i.e. by third-party application, by project, etc); I added a file “MySQL”, which simply contains “/usr/local/mysql/bin”.
The files in /etc/paths.d are processed alphanumerically, so if you need the folders in a specific file to take precedence in the path list, name the file accordingly (i.e. “0001-mysql” instead of “mysql”, to process it before “custom_app”).