Skip to content
Thu, Sep 29 2005
Tweet

HOWTO: Add a Directory to my Path Statement/Variable.

When you type the name of an executable file, GNU/Linux searches for that executable in all the directories specified in the PATH environment variable.

By default, your GNU/Linux distribution probably set up a default PATH variable during install. To see what your current PATH variable is set to, in a terminal window, type:

echo $PATH

and press ENTER. The system should respond by writing out the current value of the PATH variable. That probably looks something like:

/usr/bin:/usr/sbin

To add a directory to the PATH statement is a relatively straight forward process, but first a question needs to be answered:

Note that these instructions are for a bash shell which is very common n GNU/Linux systems. If you are running another shell, please consult the directions for that shell.

Which users do you want to be affected by this new PATH value?

  1. In a home GNU/Linux system, it’s likely that there is only one user and therefore the answer is: me and my root account.
  2. If you are running a multi-user system, then the answer is likely: everybody and root.
  3. Possibly the third answer is: only ‘joe’ or some other single user on the system.

Regardless of which user(s) are to affected, the same line(s) need to be added to a profile file. The only variable is: which file?

The line(s) or code to add are:

PATH=$PATH:/new/path (where /new/path is the directory you want to add)
export PATH

NOTE: The export command need only be called once in the profile file and after all the PATH statements in that file. If an export command is already present in the applicable profile file (see below), then you need not add another one.

You are going to add these lines to the following location depending on which user(s) you want to affect:

  1. To add that PATH to every user but root, add the line(s) to /etc/profile
  2. To add that PATH to root, add those line(s) to /root/.bash_profile
  3. To add that PATH to a specific user(s), add the line(s) to /home/user/.bash_profile
Around The Web
Loading...
Share This Post:
  • Digg
  • Facebook
  • StumbleUpon
  • Tumblr
Tweet
Pin It
Technology

Comments

  1. Trackback
    986 days ago
    Menambahkan PATH pada linux « I don’t want to be SUPERMAN…… because I’m LQman……

    [...] : https://everyjoe.com/newlinuxuser/howto-add-a-directory-to-my-path-statementvariable/ man export Tinggalkan sebuah [...]

  2. By pranay

    hi, as we can add new directories to the PATH variable,so is there any way by which we can remove any directory from the PATH variable?

  3. By balakumar

    Thanku so much for very nice artcles

  4. By Bill

    MSN I NIIPET
    MSN

  5. By conan

    I am brand new to linux (using Ubuntu 6.06) and am about to go nuts and give up on linux. All help advice I find online uses computer speak that I can’t hope to comprehend.

    SO … please, if I do not have permission to modify the profile files mentioned above, what do I do? I am trying to gain access to my NTFS drives by installing NTFS-3g, but I can’t do that bc the Synaptic package manager doesn’t have it, and the GCC compiler isn’t in my $PATH, and apparently I can’t modify that $PATH.

    Though I’m not convinced that would help me anyway, as I also can’t install the latest Firefox, which doesn’t require a compiler and yet I have zero clue (and cannot find any help files) how to install a program already in binary. So if you could help me with that too, it would be fantastic. Please please please … I’m begging.

  6. By Alex

    Thank You