export PATH doesn't work correctly

14,604

There are a few places where you can define $PATH:

  • /etc/environment is a plain text file (not a script) that affects all users
  • ~/.pam_environment - the same thing but user-specific

bash also executes some scripts which can be used for modifying $PATH:

  • ~/.profile is executed for a login shell sessions (don't ask me what it means :)
  • ~/.bashrc is executed for non login interactive shell sessions
  • /etc/profile and /etc/bash.bashrc are system wide alternatives for ~/.profile and ~/.bashrc

I read somewhere that /etc/environment is a recommended place for defining your $PATH. So I usually use it. But your path is probably modified in one of the other places.

BTW, when you execute a command with sudo, I think it normally uses root user's $PATH (and not the $PATH of your unprivileged user account). So, ~/.pam_environment, ~/.profile and ~/.bashrc in /root directory may also play a role.

Share:
14,604

Related videos on Youtube

pstrag
Author by

pstrag

Updated on September 18, 2022

Comments

  • pstrag
    pstrag over 1 year

    I have a problem with $PATH export. The only place I found where I modify $PATH is /etc/environment:

    ANDROID_HOME="/opt/ADT/adt-bundle-linux-x86_64-20130522/sdk"
    PROJECT_HOME="/home/tomaszchabinka/Dokumenty/tempFile/android_stb"
    PATH="/opt/gradle-1.10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    

    But when I type in terminal echo $PATH it returns:

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/jdk1.7.0/bin
    

    I don't have /usr/lib/jvm/jdk1.7.0/bin directory so I don't understand why my $PATH export doesn't works and where does /usr/lib/jvm/jdk1.7.0/bin come from.

    Also $ANDROID_HOME and $PROJECT_HOME exports correctly; only $PATH export doesn't work.

    Can anyone help me?

    • lazyPower
      lazyPower over 10 years
      You should be placing those types of exports in $HOME/.bashrc or $HOME/.zshrc or whichever shell dotfile corresponds to your environment. If this needs to propagate to new user accounts, place it in /etc/skel/ in the appropriate dotfile.
    • pstrag
      pstrag over 10 years
      I've tried this earlier (with .bashrc and with .profile) and also didn't work
  • Phil UK
    Phil UK about 7 years
    Welcome to the site and thank you for your input. You answer could be improved by adding a bit more, for example; what the expected result is, if it worked for you and such like.