How To Add To Path Linux

When working with a Linux operating system, you may occasionally need to add directories to your PATH. The PATH is a list of directories your shell searches through when you enter a command. This is useful, for example, if you install software in non-standard locations, or want to run scripts located in your own home directory.

The process of adding a directory to your PATH varies slightly depending on which shell you are using, but here is a general guide on how to do it.

Step 1: Identify your shell

The first step is to identify which shell you’re using. You can do this by executing the following command in your terminal:

<strong>echo $SHELL</strong>

This will return the path to your current shell. Common responses would be /bin/bash for the Bourne Again shell (bash), or /bin/tcsh for the T C shell (tcsh).

Step 2: Edit the appropriate configuration file

The next step is to edit the configuration file for your shell. This file is read and executed each time a new shell session is started. For bash, this file is typically ~/.bashrc, and for tcsh it’s usually ~/.tcshrc. Other shells have their respective configuration files.

If you’re unsure about your shell’s configuration file, consult the manual or help files for your shell.

Step 3: Add the directory to your PATH

Now, let’s add the directory to your PATH. If you’re using bash, you can add the following line to your .bashrc file (replace /path/to/dir with the actual directory you want to add):

<strong>export PATH=$PATH:/path/to/dir</strong>

Similarly, for tcsh users, you can add the following line to your .tcshrc file:

<strong>setenv PATH $PATH:/path/to/dir</strong>

These commands append /path/to/dir to the existing PATH. Make sure you don’t accidentally erase your existing PATH, or you might lose access to important system commands!

Step 4: Apply the changes

The changes you made won’t take effect in your current shell session. To apply them, you need to source the configuration file, like so:

<strong>source ~/.bashrc</strong>


<strong>source ~/.tcshrc</strong>

Alternatively, you can simply close your current terminal and open a new one. Your new PATH should now include the directory you added.


Adding directories to your PATH can make working with custom scripts and programs much more convenient. It’s a simple process, and one worth knowing if you often find yourself working in the Linux terminal.