The
PATH
is an important concept when working on the command line. It's a listof directories that tell your operating system where to look for programs, sothat you can just write script
instead of /home/me/bin/script
orC:UsersMebinscript
. But different operating systems have different ways toadd a new directory to it:Windows
There are multiple ways to do it. The actual solution depends on the purpose. The variable values are usually stored in either a list of assignments or a shell script that is run at the start of the system or user session.
- The first step depends which version of Windows you're using:
- If you're using Windows 8 or 10, press the Windows key, then search for andselect 'System (Control Panel)'.
- If you're using Windows 7, right click the 'Computer' icon on the desktopand click 'Properties'.
- Click 'Advanced system settings'.
- Click 'Environment Variables'.
- Under 'System Variables', find the
PATH
variable, select it, and click'Edit'. If there is noPATH
variable, click 'New'. - Add your directory to the beginning of the variable value followed by
;
(asemicolon). For example, if the value wasC:WindowsSystem32
, change it toC:UsersMebin;C:WindowsSystem32
. - Click 'OK'.
- Restart your terminal.
Mac OS X
- Open the
.bash_profile
file in your home directory (for example,/Users/your-user-name/.bash_profile
) in a text editor. - Add
export PATH='your-dir:$PATH'
to the last line of the file, whereyour-dir is the directory you want to add. - Save the
.bash_profile
file. - Restart your terminal.
Linux
- Open the
.bashrc
file in your home directory (for example,/home/your-user-name/.bashrc
) in a text editor. - Add
export PATH='your-dir:$PATH'
to the last line of the file, whereyour-dir is the directory you want to add. - Save the
.bashrc
file. - Restart your terminal.