Where is PATH setup in Ubuntu 16.10 bash shell?

13,965

Solution 1

Turns out the PATH was being persisted by the display manager loading ~/.profile, (and /etc/profile and /etc/environment) when creating a desktop session. This means changes to those files aren't going to reflect in new bash sessions and require logging out to take effect.

Solution 2

you can find this out by run bash in in debug and login modes , its quite enlightening

/bin/bash -xl

There is quite lot of output but you should be able to see the whole chain of loading files and modifying $PATH.

Share:
13,965

Related videos on Youtube

Carl Zulauf
Author by

Carl Zulauf

Ruby > PHP > Java ... I love them all

Updated on September 18, 2022

Comments

  • Carl Zulauf
    Carl Zulauf over 1 year

    I can't seem to determine where the bash PATH environment variable is getting setup on my fresh Ubuntu 16.10 install.

    I have tried placing echo $PATH statements at the top of ~/.bashrc and even /etc/bash.bashrc. Both echo statements get executed, so these files are loading properly, But, in both cases the PATH already contains the following:

    /home/carl/bin:/home/carl/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
    

    The first entries (/home/carl/bin:/home/carl/.local/bin) are what I'm trying to track down. I'm not really sure where any of the values are set since changing /etc/environment seems to have no effect.

    The PATH is also setup when /etc/profile executes when using a login shell and is also unaffected by changes to /etc/environment.

    • steeldriver
      steeldriver over 7 years
      Try ~/.profile
    • Carl Zulauf
      Carl Zulauf over 7 years
      It's not ~/.profile. That isn't executed at all in an interactive non-login shell.
    • Gunnar Hjalmarsson
      Gunnar Hjalmarsson over 7 years
      @CarlZulauf: In a desktop session it's sourced by the display manager (lightdm). So it's most certainly the file in question.
    • Carl Zulauf
      Carl Zulauf over 7 years
      @GunnarHjalmarsson you are correct. I didn't realize the desktop session itself loads ~/.profile (which explains why gnome-terminal defaults to non-login shells) and requires logging out to take effect. Sorry @steeldriver for not understanding why you were correct.
  • Gunnar Hjalmarsson
    Gunnar Hjalmarsson over 7 years
    To be more precise: /etc/environment is read by PAM and not sourced by anything. /etc/profile and ~/.profile are sourced by lightdm, but the former is not involved in setting environment variables by default.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 7 years
    Congrats on answering your own question. Don't forget to accept it as the solution in two days so others know it's the accepted answer.