Export Paths
This page was last updated on October 25, 2009.
Introduction
There may come a time when someone will give you instructions to do something on the command line, and part of those instructions will involve exporting a path. This may sound somewhat ominous at first (it did to me), but it turns out that exporting paths can be quite useful.
When you export a path, you’re making it available to the operating system. You can export a path temporarily to make it available for the current terminal session, or you can export it permanently.
As an example, let’s say that you like to write Bash scripts, you keep them in the /home/username/scripts directory, and you run them from time to time. To run any of the scripts, you would open a terminal window, change to the /home/username/scripts directory, and type the command to run the script, or you would open a terminal window and type the command to run the script, including the full path to the /home/username/scripts directory as part of the command.
To make life easier, you could export the path to the /home/username/scripts directory so the sytem can use it automatically. From then on, to run any of the scripts, you would open a terminal window and type the command to run the script. Notice that you no longer need to change to the directory the scripts are in or add the full path to the command.
Display the paths I’m currently exporting
- Type this command to display the paths that are currently being exported:
echo $PATH
- Example output:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
This means that files in these directories are in your path:
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
Export path temporarily
This will temporarily export a path until you close the current terminal session. Whatever path you export will be added to the exported paths your system currently has (see above for displaying the paths you currently have exported) rather than replacing them.
- Open a terminal window and type this command, replacing pathtodirectory with the path to the directory you’d like to export:
export PATH="$PATH:/pathtodirectory"
- Example:
export PATH="$PATH:/home/littlegirl/Documents"
export PATH="$PATH:/pathtodirectory1:/pathtodirectory2:/pathtodirectory3"
- Example:
export PATH="$PATH:/home/littlegirl/scripts:/home/littlegirl/bin:/home/littlegirl/myprograms"
Export path permanently
This will make an export permanent so that you don’t have to export it temporarily every time you open a terminal session.
- Open your /home/username/.bashrc file in a text editor:
- From the GUI:
- Enable Show hidden files in your file manager.
- Open your /home/username directory.
- Left-click or double left-click (depending on your settings) the file, or right-click it and select the Open with option and choose a text editor.
- From the command line:
- Ubuntu users type this command, replacing username with your user name:
gedit /home/username/.bashrc
- Kubuntu users type this command, replacing username with your user name:
kate /home/username/.bashrc
- From the GUI:
- Look for this line in the file:
- If it’s there, insert this line above it, replacing pathtodirectory with the path to the directory you’d like to export:
- If it’s not there, insert these two lines at the bottom of your /home/username/.bashrc file, replacing pathtodirectory with the path to the directory you’d like to export:
- Example:
- To add more paths, insert more PATH lines above the export PATH line:
- Save the file.
- Close the file.
- Open a terminal window and type this command to verify that you exported the paths properly:
export PATH
PATH="$PATH:/pathtodirectory"
PATH="$PATH:/pathtodirectory" export PATH
PATH="$PATH:/home/littlegirl/scripts" export PATH
PATH="$PATH:/pathtodirectory1" PATH="$PATH:/pathtodirectory2" PATH="$PATH:/pathtodirectory3" export PATH
echo $PATH
You should see the directories you exported at the end of the path line.
Obligatory Happy Ending
And they all lived happily ever after. The end.

Comment: