How to set the PATH in Terminal?

As a newbie to Bash and the Terminal, in connection with installing a new version of Ruby and various add-ons, I have been messing around with changing the PATH via various methods I've found on the internet, and trying to add a new directory to my PATH. Unfortunately, I cannot figure out how to set the PATH correctly. Here is what I understand so far:

1. Bash first looks to ".bash_profile" in the home directory for PATH settings.
2. If none, Bash then looks to ".bash_login" for PATH settings.
3. If none, Bash then looks to ".profile".
4. If none, Bash then looks to a system file in "/etc/profile" for default PATH settings.
5. For a new shell after login, Bash looks for a ".bashrc" file.

I cannot find any of the above files (I have Finder set to show hidden files already). Somehow, following some instructions from the internet without really knowing what I was doing over the past week I have set my PATH as follows:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/ *****/src:/usr/X11/bin

but I cannot find the file that is setting this PATH. I have tried creating a new ".bash_profile" shell file and putting it in various places such as "/bin" and "/usr/bin" but the file is not being read.

* As a temporary workaround I tried using the command "source .bash_profile" upon login to set the PATH using the .bash_profile file that I created, but it does not work.
* I am able to temporarily alter the path using the command "PATH=/usr/local/bin:$PATH" but this only lasts for an active shell; when I close out and reopen a new shell, it reverts to the default.

So my questions are:
Is it correct that there is a "/etc/profile" somewhere that is setting the default PATH? If so where is it? Should I alter it, or create a new ".bash_profile" somewhere to set the PATH? If not, where is my PATH being set? If I should create a new ".bash_profile", what exactly should go in it?

Thanks in advance for any assistance.

iMac, Mac OS X (10.6.4), Terminal 2.1.1

Posted on Sep 14, 2010 3:58 PM

Reply
17 replies

Oct 3, 2010 4:43 PM in response to BobHarris

BobHarris wrote:
PATH=$HOME/bin:$PATH

You have '/bin/' in your Home directory? Doesn't sound right.

It is VERY common to have a personal script/utilities directory called ~/bin and add $HOME/bin to your PATH.


Didn't know that. Whenever I install a program it gets installed in /usr/loca/bin, and I put any personal scripts in $HOME/Library/Scripts. Thanks.

Oct 3, 2010 6:17 PM in response to Tony T1

You are an administrator, and have the ability to put stuff in /usr/local/bin. However, in days of old, Unix systems had 100's (1000's) of users sharing the single system, and if you wanted personal shell scripts or programs, you had to put them into your home directory somewhere. It was very common to create a ~/bin for this.

Today, many Unix systems are controlled by one person (or an admin team) where just about everyone has admin privs (or the ability to impose Parental Controls 🙂 ).

However, in some corporate environments, your Unix home directory is on a server somewhere, and is NFS automounted on the corporate Unix system you login to. The /usr/local/bin is also a READ ONLY NFS mounted directory where corporate approved apps are shared. So again, if you want your own personal shell scripts and programs you put them somewhere in your home directory (~/bin being a traditional place). There is an advantage in that if corporate did not take over /usr/local/bin, then that would be specific to a single machine, but if your personal stuff is in your NFS automounted home directory, you will have all your stuff with you no matter what Unix system you login to.

For example, at my company, my NFS automounted home directory is the same whether I login to a Linux, Solaris SPARC, Solaris intel, or AIX system. I put scripts into ~/bin, and I put compiled executables into an OS/architecture specific directory that I dynamically add to my PATH when I login.

So while it is not really necessary to have a ~/bin, if you live (or have lived) in one of the above environments, you tend to follow conventions that have worked in the past.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to set the PATH in Terminal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.