Before setting a PATH variable, you need to understand why you are setting the PATH variable. The Path variable is where the system tries to search when you issue some command in your terminal.
Example: whereis ls
command shows ls
is there inside /bin
.
The ls
command only works if /bin
is registered in the path variable.
echo $PATH
gives the currently registered locations. If you want to add another custom location to your path variable there are several ways you can try.
PATH="$PATH:/someLocation"
New Path variable is only valid till your terminal closes. No other terminal will be affected. No subprocess can use the new variable.
export PATH="$PATH:/someLocation"
New Path variable is valid till your terminal close also all subprocesses will get the new Path variable. No other terminal will get a new variable.
export PATH="$PATH:/someLocation"
Add this line into the .bashrc
file present in your home folder. Which is called every time a new bash shell is created. This means you get a new Path variable exported every time a new terminal is opened. But this variable is created for only bash shells. You can use the old Path variable in other shells(ksh, sh, ssh ..).
export PATH="$PATH:/someLocation"
Add this line into the .profile
file present in your home folder. Which is called every time you log in. This means you get a new Path variable exported every time your session is created. Which is available everywhere.
If you can't find the .profile
or .bashrc
file in your home folder, try to create a new one. Sometimes these files won't be created by the system.
ps: Works in ubuntu. Open to any corrections.