To set the environment variable in Linux permanently, you can insert the export command into startup file.
Example of command to set environment variable:
export JAVA_HOME=/usr/local/java/jre1.8
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)
- /etc/profile
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)
- /etc/.bashrc
- ~/.bashrc
Example:

Reference: https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/