I am trying to install something and among the steps there was this one:
"Place it on your $PATH
"
What does this mean? What is that?
I have searched both this site and on Google but everyone just takes it for granted!
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityI am trying to install something and among the steps there was this one:
"Place it on your $PATH
"
What does this mean? What is that?
I have searched both this site and on Google but everyone just takes it for granted!
Run in a terminal:
echo $PATH
or
printf "%s\n" "$PATH"
what you see is a list of directories, looking like:
/home/jacob/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
If you put an executable in either one of these directories, you do not need to set the path to the executable / script, but you can run it by its name as a command.
Executables in $PATH
should not have a language extension by convention (although they would work)
You can (permanently) add a directory to $PATH
by adding the following line to your ~/.profile
file (invisible by default, press Ctrl+H in the file manager to make it visible):
export PATH=$PATH:/path/to/dir
(such as $PATH
) can be found here (thanks for the suggestions @Letizia)
$PATH
is a environment variable that is file location-related.
When one types a command to run, the system looks for it in the directories specified by PATH
in the order specified.
You can view the directories specified by typing echo $PATH
in the terminal.
Suppose there is a executable file foobar01.sh
present at /home/user/foo1/foo2/foobar01.sh
which you want to execute on a regular basis. typing the entire "path" would be time consuming. So we add the directory in to $PATH
variable and we can execute foobar.sh
directly without even specifying the path.
You can add it to $PATH
by typing the following command:
export PATH=$PATH:/home/user/foo1/foo2
I assume you are coming from a Windows background (apologies if it is not true). In layman's terms, a path (or the search path) is the list of directories that will be searched for anything that you type on the command line. If you type in a built-in command like ls, it will look for a specified list of directories. You can look up your path by typing echo $PATH. Here is one difference between Windows and *nix: By default, Windows always looks for the executable file in the current directory. For example, if you have a file called uptime.bat in c:\myscripts, and you cd c:\myscripts and type in uptime, it will run. However, in *nix, the path will be consulted and the executable found (if available).
If you keep your scripts in a directory called /home/teresa/scripts, to execute those scripts, you will have to specify the full path to that directory. Example: /hone/teresa/checkHost. A variation would be to cd /home/teresa and then type ./checkHost (note the ./ which means that you are explicitly asking the file to run from the current directory.
To avoid this, you can just type
export PATH=$PATH:/home/teresa/scripts
which means that, in addition to the path that already exists now, also search in /hone/teresa/scripts. However, the problem with this is that once you logout, this setting would be gone. So, you should edit the hidden file ~/.bashrc, find the PATH line there, and append it accordingly. I am assuming you use bash. In the case of other shells, the syntax and file are different.
As a new user, it is very tempting to have . in the search path, which basically means that also search in the current directory. However, that is not considered a good practice for reasons discussed elsewhere.
HTH