PATH

How the system path is set is quite complicated, depending on your system and shell setup.

But for the most common one (Linux Mint/Bash in my case), here it is. Shamelessly copied from (https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux-unix)

System wide

  1. /etc/environment List of unique assignments, allows references. Perfect for adding system-wide directories like /usr/local/something/bin to PATH variable or defining JAVA_HOME. Used by PAM and SystemD.
  2. /etc/environment.d/*.conf List of unique assignments, allows references. Perfect for adding system-wide directories like /usr/local/something/bin to PATH variable or defining JAVA_HOME. The configuration can be split into multiple files, usually one per each tool (Java, Go, NodeJS). Used by SystemD that by design do not pass those values to user login shells.
  3. /etc/xprofile Shell script executed while starting X Window System session. This is run for every user that logs into X Window System. It is a good choice for PATH entries that are valid for every user like /usr/local/something/bin. The file is included by other script so use POSIX shell syntax not the syntax of your user shell.
  4. /etc/profile and /etc/profile.d/* Shell script. This is a good choice for shell-only systems. Those files are read only by shells in login mode.
  5. /etc/<shell>.<shell>rc. Shell script. This is a poor choice because it is single shell specific. Used in non-login mode.

User session

  1. ~/.pam_environment. List of unique assignments, no references allowed. Loaded by PAM at the start of every user session irrelevant if it is an X Window System session or shell. You cannot reference other variables including HOME or PATH so it has limited use. Used by PAM.
  2. ~/.xprofile Shell script. This is executed when the user logs into X Window System system. The variables defined here are visible to every X application. Perfect choice for extending PATH with values such as ~/bin or ~/go/bin or defining user specific GOPATH or NPM_HOME. The file is included by other script so use POSIX shell syntax not the syntax of your user shell. Your graphical text editor or IDE started by shortcut will see those values.
  3. ~/.profile~/.<shell>_profile~/.<shell>_login Shell script. It will be visible only for programs started from terminal or terminal emulator. It is a good choice for shell-only systems. Used by shells in login mode.
  4. ~/.<shell>rc. Shell script. Used by shells in non-login mode. This is where you add most of your private edits.

Very useful PATH tool

Add this to your ~/.bashrc

function path(){
  old=$IFS
  IFS=:
  printf "%s\n" $PATH
  IFS=$old
}

then you call just type “path” in your terminal to get the PATH printed nicely, line by line.

Finally

Remember that if you change some (specifically the System) settings above, you might have to reboot! If you do changes to the system path, and reopen a terminal and “nothing happens”, then try a reboot! I know it doesnt come easy to a seasoned Linux user to casually restart the machine (heck we’re not poor Windows users) but every once in a while you can cope with it! Some settings might be cached you know!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.