Switch Linux JDK version

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容