As a Linux user you can add directories to your $PATH. This is helpful when you don’t want to add a command to a directory in your $PATH but you want that command to be globally executable. Doing this is actually quite easy.
What is currently in your $PATH?
NOTE: This article applies only when you are using the Bash shell. To find out what directories are included in your current $PATH issue the command:
echo $PATHYou should see something like:
/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jlwallen/binNotice the /opt directory is missing. Often the /opt directory is a great place to “install” other applications for global use. But if this directory is not in your $PATH, you will always have to use the explicit path to call a command. With that in mind let’s add /opt..bash_profile
In order to add a directory you have to edit a file in your ~/ (home) directory. The .bash_profile file determines user specific environment and start up programs. This file also checks for a .bashrc file for aliases and functions, but that has nothing to do with your $PATH.
There is one particular line you need to examine in your .bash_profile:
PATH=$PATH:$HOME/binThis is the line that determines anything extra in your $PATH. As you can see, in the example above, the extra directory added to the users’ $PATH is the ~/bin directory. Of course in most distributions this isn’t used (or even created during installation). Why ~/bin is still included I do not know. In order to add another directory to your $PATH in this line you would seperate the directories with a “:”. To add the /opt directory that line would now look like:
PATH=$PATH:$HOME/bin:/optAs you can see the /opt directory has been added proceeding a “:”. Complete this addition and save the file. You’re not done yet.If you issue the command echo $PATH you will still not see /opt in the users’ $PATH. Why? You have to log out and log back in before this change will take effect. So log out, log back in, and issue the command again. Issuing the command echo $PATH will not issue:
/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jlwallen/bin:/optAny command found in the /opt directory is now global.Final thoughts
The $PATH is a very powerful tool to take advantage of in Linux. By using it you can install applications in directories outside of the norm and still make them global. I often install applications in the /opt directory or will create a /data directory for a more temporary application installation.












