Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PATH environment variable in Linux

I want to know how the standard environment variables given by the Linux OS like PATH, HOME are set automatically. Which file(s) are these read from. There should be some file from which these variables are set when a particular user logs in.

like image 980
pradeepchhetri Avatar asked Sep 22 '11 06:09

pradeepchhetri


1 Answers

I would like to add a few more details to what @cnicutar has already mentioned.

Environment variables including PATH can be:

  • System wide - The values of the environment variables last till the system is up
  • Session wide - Lasts till a session lasts (till user logs out)

/etc/profile is meant for system settings for Bourne & Bourne compatible shells. The behavior of /etc/profile may vary across distributions.

For the latest Ubuntu distributions, it is recommended to use /etc/environment for system-wide settings. It is not recommended to use /etc/profile or /etc/bash.bashrc as noted the Ubuntu help.

On Ubuntu machines, /etc/profile is a shell script which sources the scripts in /etc/profile.d and the system-wide bashrc file in /etc/bash.bashrc, whereas /etc/environment is a text file consisting of variable assignments per line which are set into the system-wide environment.

For each user the values of environment variables including PATH (for the shell) can also be manipulated through ~/.profile, ~/.bash_profile, ~./bash_login, and ~/.bashrc where ~ means the user's home directory, like /home/alex/.

To see your current environment variables and their values, you can use printenv.

You can refer to the following link for more details on environment variables on Ubuntu systems: https://help.ubuntu.com/community/EnvironmentVariables

like image 139
another.anon.coward Avatar answered Oct 13 '22 12:10

another.anon.coward