It’s very trouble-free task to edit/ change the path environment variables on Mac OS X.
The recommended way is by editing your .bash_profile file.This file is read and the commands in it are executed by bash every time you log in to the system.The best part is that this file is specific to your user so you won’t affect other users on the same system by changing it.
Step 1: Open up a Terminal window (this is in your Applications/Utilites folder by default).
Step 2: Enter the following command:
This will open the .bash_profile file in TextEdit(the default text editor included on your Mac). This file allows you to customize the environment your user runs in.
you can enter the following command:
This will open the .bash_profile in TextEdit or TextWrangler whose contents can be edited as you like.Also you can use
cat .bash_profile which will output the contents of the file directly into the terminal window so that you can review it.
Note: With cat command you cannot edit the file but you can have a look at the contents.
Step 3:Add the following to the end of the file adding whatever additional directory you want in your path:
For instance, export PATH=”$HOME/.rbenv/bin:$PATH”
This example would add ~/.rbenv to the PATH.The $PATH part is very important as it appends the existing PATH to preserve it in the new value.
Step 4: Save the .bash_profile file and quit (Command+Q) TextEdit or TextWrangler in this illustration.
Step 5: Force the .bash_profile to execute.This loads the values immediately without having to reboot.To execute the file ,run the following command in your terminal window.
That’s it!Mission accomplished and now you know how to edit/change the PATH on your Mac OS X.
Step 6: You can confirm the new path by executing the following command:
Now you will see the changes which you have made.
Mistakes one can make while following this process:
If you type ~/.bash_profile in your terminal window you would land on this following statement which says
-bash: /Users/<your username>/.bash_profile: Permission denied
It’s saying ‘permission denied’ because you are trying to run the .bash_profile as a command.When you type ~/.bash_profile you haven’t given it a command to execute against the file.
As the filename starts with the ‘.’ ,it is a hidden file.In terminal if you type ls -la it will give you a listing with all the files in a directory with a long format which provides more information about the files including the ownership privileges including all the hidden files.
So beware of making such a mistake! Have fun 🙂