How to Set Environment Variables in Linux
You can put the export statement such as
/etc/profile File for Linux system wide environment
~/.bash_profile ($HOME/.bash_profile) or ~/.prfile file For only this account's environment.
The above only runs for login shell. If you wanted to make large changes or application specific changes, you can try putting a script to gather the variables in /etc/profile.d/
$ cat java.sh
/etc/profile does a call that will run any script in /etc/profile.d/, and this applies to all users on the system including root.
If you want to load the environment variables within java.sh without having to restart the machine, you can use the source command as in:
$> source java.sh
Check to make sure it works
And you can use
to display current environment.