If you have downloaded some custom binary (external program) and want to access it from terminal irrespective of your current working directory, probably you are looking for PATH variable in Linux.
PATH is an environment variable which contains a list of directories separated by
When I typed
echo $PATH it shows me
Oh, wait! But what are these folders, and what is their use?
These are the folders which contains binaries of programs installed on my machine.
echo $PATH may be different for you based on your Linux distros and program you have installed.
So whenever I typed any command in the terminal, OS will start finding that program one-by-one into these directories, whenever it found first match, it will open it. If it can't find the given command it will display an error
command not found.
Okay now that make sense!
But you have not answered my original question till now? I have installed a new program and I want to access it using terminal from any working directory. How can I do that?
A simple solution for this is to add the path of your new program to the environment variable $PATH.
Let's do it with an example.
I have recently downloaded flutter package and unzip it. But when I typed
flutter I can't access it. To get this working I have to update the $PATH variable, something like this
and bingo. Now if you type
flutter in terminal you can access it from anywhere.
Are these changes are permanent, what if I close the terminal or shut down my machine, will they persist?
And the answer is NO.
Okay! So what is the permanent solution?
Permanent solution is update path variables via updating terminal profile/settings, I am using bash shell so to update bash setting I will update
.bashrc file, If you are using zsh or any other terminal please update its respective profile/settings file.
Use the same command
and add it to the end of the
.bashrc file and save the file.
Now these changes are permanent even if you shut down or restart your machine.
- What is $PATH variable?
- Update terminal settings file, for bash it is .bashrc
- How to access any program from any working directly in the terminal.