When we do CTS test or GTS test,usually it requires different JDK versions.
For example,if we already have JDK 1.7 and we need to use JDK 1.8,then we can simply use command to do this instead of downloading a higher version from the internet.
1. Do upgrade
sudo apt-get update
sudo apt-get install oracle-java8-installer
Or if you have no jdk to update,do this
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt install oracle-java8-set-default
2. Modify bashrc
After this,we need to modify the path.
Try to cat bashrc .
cat .bashrc
Modify bashrc
vi .bashrc
At first it may look like this at the bottom:
JAVA_HOME=/usr/lib/jvm/java-7-oracle
JRE_HOME=/usr/lib/jvm/java-7-oracle/jre
After modifying it may look like this at the bottom:
#JAVA_HOME=/usr/lib/jvm/java-7-oracle
#JRE_HOME=/usr/lib/jvm/java-7-oracle/jre
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
3. Save the changes
source .bashrc
4. Now close the terminal,open a new one
java -version
And finally,we can see the version is 1.8.
Again if we need to use 1.7,just modify bashrc.
From
#JAVA_HOME=/usr/lib/jvm/java-7-oracle
#JRE_HOME=/usr/lib/jvm/java-7-oracle/jre
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
To
JAVA_HOME=/usr/lib/jvm/java-7-oracle
JRE_HOME=/usr/lib/jvm/java-7-oracle/jre
#JAVA_HOME=/usr/lib/jvm/java-8-oracle
#JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
And of course always remember to save the changes.
Besides,if you have both java7 and java8,and wish to switch the version,just do this:
sudo update-alternatives --config java