How to set PATH variables Linux, Bash

Hey there, this is a classic question in Linux systems.

It shows whenever you wanna run certain command and you get


admin@yourserver:~$ whatever
bash: whatever: command not found

You need to add ‘whatever’ (or the program you want) path into your current path

To see your current path do this


admin@yourserver:~$ echo $PATH
/usr/local/bin:/bin:/usr/local/games:/usr/games

You can see my current path, lets say I want to add /usr/bin I will do this

PATH=$PATH:/usr/bin

note: You don’t need export if the variable is already exported: any change of the value of the variable is reflected in the environment. (This wasn’t true in older shells, but you’re highly unlikely to encounter such old shells these days.)
Check this post for more info

Now you can check again


admin@yourserver:~$ echo $PATH
/usr/local/bin:/bin:/usr/local/games:/usr/games:/usr/bin

Check how /usr/bin was added to the end.

And that’s it very easy and useful, next time just call command by name instead of full path 😉

Leave a comment