I am using RHEL 6.8. Is it possible to set up a 1.8 server JRE path in JAVA_HOME in Linux when the JDK is 1.7.0_45? I need both of the java versions and two JAVA_HOME.
Thanks in advance!
The typical way to handle such things is by using alternatives.
Meaning: it is absolutely no problem to have multiple JREs/JDKs on the same system; you just need to manage them; and alternatives helps with that.
For Redhat, have a look into their documentation.
You can have 2 version but you can use only one at a time or create 2 system user with different profile as mentioned below:
/usr/local/java/ - jdk1.8.0_60 - jre1.7.0_60
1) vim ~/.profile or vim ~/.bash_profile
2) Add below lines at end. Please check your jdk/jre path and change it accordingly
export JAVA_HOME=/usr/local/java/jre1.7.0_60
export PATH=$JAVA_HOME/bin:$PATH
3) exit vim editor
4) echo $JAVA_HOME
you will require to logout from system and login again.
if you want to switch it to jdk1.8.0_60 then edit the same file ~/.profile or ~/.bash_profile and follow the above procedure again.
You can't really have two JAVA_HOME environmental variables in the same Linux environment (the env variables are basically key-value entries, thus you can't have to entries with the same key JAVA_HOME).
I suggest the solution I wrote here: https://stackoverflow.com/a/50766853/6661361
In few words:
Install all your java alternatives:
sudo update-alternatives --install /usr/bin/java java /home/aqeel/development/jdk/jdk1.6.0_35/bin/java 1`
Add the following snippet to your ~/.bashrc (or other bash configuration file, depending on the scope you want to use):
export JAVA_HOME=$(update-alternatives --query java | grep Value: | awk -F'Value: ' '{print $2}' | awk -F'/bin/java' '{print $1}')
Choose you java version with the following command:
sudo update-alternatives --config java
Your JAVA_HOME should change automatically (just remember to open a new command terminal after changing the java version, or create a script to do it manually).
Optionally: if you have to change the java version constantly, you might want to consider adding an alias to your ~./bash_aliases:
alias change-java="sudo update-alternatives --config java"
(You might have to create the file and maybe uncomment the section related to this in ~/.bashrc).