Friday, April 22, 2016

How To Edit Your PATH Environment Variables On Mac OS X



If you are a new Mac OS X user and you want to edit your PATH Environment Variables then you are in right place. This can be done easily by following the steps bellow.

The recommended way is to editing your .bash_profile file because this way you need not update your PATH Environment Variables using export command every time you login to your mac. This file is read and the commands in it 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/Utilities folder by default)
(or) 
To open a Terminal window -> press buttons :   command & space bar ( ⌘ + space )
A Spotlight Search will show up and the type "Terminal"

Step 2: Enter the follow commands:

touch ~/.bash_profile; open ~/.bash_profile

This will open the .bash_profile file in default text file editor "Text Edit". The file allows you to customize the environment your user runs in.

Step 3: Add the following line to the end of the file adding whatever additional directory you want in your path:

export PATH="<your_path>:$PATH"

Example: export PATH="~/.npm-global/bin:$PATH"

That example will add ~/.npm-global/bin to the PATH. The $PATH part is important as it contains the existing PATH to preserve it in the new value and appending it at the end will concatenate the new path with the existing path. if you remove $PATH part at the end of the command this will replace the existing path with new path and this will effect your system and it can not run most of the regular commands.

Step 4: Save the .bash_profile file using ( ⌘ + S ) and Quit ( ⌘ + Q ) Text Edit.

Step 5: Now force the .bash_profile to execute. This updates the PATH Environment Values immediately without having to reboot. In your Terminal window, to do so run the following command.

source ~/.bash_profile


That’s it! Now you know how to edit the PATH on your Mac OS X computer system.

To can confirm the new path by opening a new Terminal windows and running:

echo $PATH

You should see the updated PATH now.


0 comments:

Post a Comment