Wednesday, 8 August 2012

Adding PATH to Unix based systems (Linux, Mac OS)

The terminal or the Console on the Unix based systems like Linux or Mac OS is a great tool for whom do want to use the keyboard instead of the mouse.

The PATH is an environment variable which defines the source where the terminal looks for the programs which the user invokes. This variable could be modified. For example, for the case of Android, it could be a great tool to access ADB from the terminal.

1. Check the content of the PATH
To check the actual content of the variable, the user should type:

echo $PATH

2. Modify the value of the PATH temporary
Like any environment variable, the value of PATH could be easily modified using the command "export". For example, the follow command adds the path /Applications/eclipse/plugins/android-sdk-macosx/platform-tools/ to the existence PATH.

export PATH=$PATH:/Applications/eclipse/plugins/android-sdk-macosx/platform-tools/

The command above indicates that the new value for PATH should be the old one ($PATH) appended (:) to the new value (/Applications/eclipse/plugins/android-sdk-macosx/platform-tools/). Be careful with the command export, which replace the actual value of the PATH by the new one.

The modification from the terminal is useful for the actual terminal. If the user opens a new terminal, it will open with the default settings. If the new path must be added permanently to the environment, the follow step should be followed.

3. Modify permanently the value of the PATH
In order to modify permanently the value of the environment variable PATH, a file is needed.

This file must be stored in the HOME directly, which could be easily acceded typing the command "cd".
3.1 Go to home directly. Type the follow command in the terminal:

cd

3.2 Opens the .profile file

nano .profile

Nano is a text editor which could be used with the terminal. In this case, if the file does not existes, it will creates a new one. Otherwise, it will open the existence one.

3.3. Go to a new line of the file and copy the follow text:

export PATH=$PATH:ANEWPATH

where "ANEWPATH" is the path which should be added. For example, the follow line adds the directly /Applications/eclipse/plugins/android-sdk-macosx/platform-tools/ to the variable PATH.

export PATH=$PATH:/Applications/eclipse/plugins/android-sdk-macosx/platform-tools/

3.4 Close the file and save it
Press on the buttons Ctrl and O at the same time to save the modifications
Press on the buttons Ctrl and X at the same time to close the text editor.

3.5 Restart the terminal
Close the terminal and start it again. Now, if the terminal receives the command

echo $PATH

It must shows the old paths with the new path.

No comments:

Post a Comment