Making environment variables persistent On Linux
Now that you know you way around the various shell process types and their various environment files, locating the permanent environment variables is much easier. You can also set your own permanent global or local variables using these files.
For global environment variables (those variables needed by all the users on a Linux system), it may be tempting to put new or modified variable settings in the /etc/profile, but this is a bad idea. The file could be changed when your distribution is upgraded, and you would lose all the customized variable settings.
It is a better idea to create a file ending with .sh in the /etc/profile.d directory. In that file, place all your new or modified global environment variable settings.
On most distributions, the best place to store an individual user’s persistent bash shell variables is in the $HOME/.bashrc file. This is true for all shell process types. However, if the BASH_ENV variable is set, keep in mind that unless it points to $HOME/.bashrc, you may need to store a user’s variables for non-interactive shell types elsewhere.
Making environment variables persistent On Linux |
For global environment variables (those variables needed by all the users on a Linux system), it may be tempting to put new or modified variable settings in the /etc/profile, but this is a bad idea. The file could be changed when your distribution is upgraded, and you would lose all the customized variable settings.
It is a better idea to create a file ending with .sh in the /etc/profile.d directory. In that file, place all your new or modified global environment variable settings.
On most distributions, the best place to store an individual user’s persistent bash shell variables is in the $HOME/.bashrc file. This is true for all shell process types. However, if the BASH_ENV variable is set, keep in mind that unless it points to $HOME/.bashrc, you may need to store a user’s variables for non-interactive shell types elsewhere.
Note
Keep in mind that user environment variables for graphical interface elements, such as the GUI client, may need to be set in different configuration files than where bash shell environment variables are set Recall back in Chapter 5 that command alias settings are also not persistent. You can also store your personal alias settings in the $HOME/.bashrc startup file to make them permanent.
0 Response to "Making environment variables persistent On Linux"
Post a Comment