Ask Your Question

Setting permanent PATH

asked 2014-04-06 04:59:58 -0600

Oded gravatar image

updated 2014-04-17 02:49:06 -0600

Ahmad Samir gravatar image

Hello, i was trying to add a specific path to the PATH enviroment variable. I read some answers about this, but didnt succeed. Right now, although the file "/etc/profiles" contains the desired path, when i type:

# echo $PATH

i don't see it. i was looking to add it to the files "/etc/profile" and "/etc/bashrc" as well, but didnt find where.

Please help, Oded

edit retag flag offensive close merge delete


So, how do i set a permanent change to PATH?

Oded gravatar imageOded ( 2014-04-06 07:53:38 -0600 )edit

If you want to change the PATH env var for just one user, revert the changes you did in /etc/profile and instead edit ~/.bash_profile.

By default you should find these two lines in ~/.bash_profile:


export PATH

for example in this case $HOME/bin is added to the PATH env var. Note that you'll need to log out / log in for the changes to take effect in bash sessions (or you can source ~/.bash_profile manually until you log out / log in).

Ahmad Samir gravatar imageAhmad Samir ( 2014-04-06 11:02:35 -0600 )edit

Thanks for your answer, but i think i don't have this file. Anyway, not in /ect and not in / And, i would like to set the PATH env var to all users.

Oded gravatar imageOded ( 2014-04-07 02:23:34 -0600 )edit

@Ahmad Samir - looks like you have all the info for a very thorough answer!

randomuser gravatar imagerandomuser ( 2014-04-17 00:29:21 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2014-04-07 03:00:08 -0600

Ahmad Samir gravatar image

updated 2014-04-17 02:48:40 -0600

~ is your home directory, so ~/.bash_profile is in your home dir and it's created by default when you create a user account.

To add a custom path to the PATH env var for all users, you can edit /etc/profile and/or /etc/bashrc but I think it's better to create a file under /etc/profile.d/ e.g. /etc/profile.d/ (the name doesn't matter but the extension must be .sh), and put this in it:

export PATH
edit flag offensive delete link more


Thanks! Even if an answer is covered in more broad terms by another, it can be helpful for people looking for a specific answer to have some overlap.

randomuser gravatar imagerandomuser ( 2014-04-17 14:14:25 -0600 )edit

answered 2015-01-17 14:00:27 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Ahmad Samir is right for the following reasons: 1. Security. 2. It is cleaner because it promotes modularity. However to activate and test immediately without loging out you can make the settings available to the shell environment by sourcing as follows:

source /etc/profile.d/ or using sh interpreter sh /etc/profile.d/ or using bash interpreter bash /etc/profile.d/ or use . command . /etc/profile.d/ it will execute the script in the current shell without forking a sub shell. In other words, this executes the commands specified in the scriptfile in the current shell, and prepares the environment for you.

Cheers Robinson G. G.

edit flag offensive delete link more

answered 2016-08-01 12:39:20 -0600

ptrck4193 gravatar image

As indicated by /etc/bashrc and /etc/profile, create in /etc/profile.d/ by executing

  1. touch /etc/profile.d/

  2. chmod +x /etc/profile.d/

This file is not a sytem file such as /etc/bashrc, but customed (hence the name) to the user such as ~/.bashrc. Enter into this file the following (not my actual file, just a demonstration)

>  if shopt -q login_shell; then
>    printf '%s %s\n  %s\n' 'Loading /etc/profile.d/'\
>      '(See /etc/bashrc or /etc/profile)...'\
>      'Invoking interactive login shell...'
>    if [ "$TERM" = "linux" ]; then
>      printf '%b %s%b\n' "\E[32mHi $USER from Virtual Console" `tty` "\E[0m"
>    fi
>    printf '%s:\n' 'Set following ENV variable(s)'
>    printf '  %s\n' '1. SAMPLE_VAR1'
>    SAMPLE_VAR1="From file /etc/profile.d/, a sample variable."
>  else
>    printf '%s %s\n  %s\n' 'Loading /etc/profile.d/'\
>      '(See /etc/bashrc or /etc/profile)...'\
>      'Invoking interactive non-login shell...'
>    printf '%s:\n' 'Set following ENV variable(s)'
>    printf '%s\n' '1. SAMPLE_VAR2'
>    SAMPLE_VAR2="From file /etc/profile.d/, a sample variable."
>    if my_bin=$(echo $PATH | grep "$HOME/bin"); then
>      printf '%s\n' "Path to \"${my_bin##*:}\" already set."
>    else
>      PATH=$PATH:$HOME/bin
>    fi
>  fi

Into the files

  1. /etc/bashrc (system; interactive non-login; functions and aliases)
  2. /etc/profile (system; interactive login; environment variables)
  3. ~/.bashrc (user; interactive non-login; functions and aliases)
  4. ~/.bash_profile (user; interactive login; environment variables)

enter, for example,

"# My Section"

"printf '%s\n' 'Loading /etc/bashrc...'"

"# Done My Section"


  1. CTRL+ALT+F3 for text mode (Virtual Console)
  2. Open new terminal in graphical mode thereby starting a new bash session (pseudo-terminal)
  3. In the pseudo-terminal, enter su - (Super-user: if you have the privelege)

Caveat: don't put environment variables into ~/.bashrc; use

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-04-06 04:59:58 -0600

Seen: 43,022 times

Last updated: Jan 17 '15