To set the environment variable in Linux permanently, you can insert the export command into startup file.
Example of command to set environment variable:
There are several startup files in Linux environment.
To set environment variable for a particular user, you can use ~/bashrc, ~/bash_profile or ~/bash_login.
If you plan to set system wide environment variable, you can use /etc/profile, /etc/bashrc, etc/profile or create a custom .sh file in profile.d folder.
Here the execution sequence of the startup files:-
Interative login shell (e.g login remotely via ssh)
1.1 all the .sh files in /etc/profile.d (*if any)
- ~/.bash_profile or ~/.bash_login or ~/.profile (*executes only the first of those files found)
Interactive non-login shell (e.g Gnome terminal)