【Open-JDK】配置java的Open-JDK环境

1.安装jdk命令:
 sudo -E add-apt-repository ppa:openjdk-r/ppa -y
 sudo -E apt-get update
 sudo -E apt-get install openjdk-8-jdk

2.完成以后,使用以下命令配置以下java和javac
sudo update-alternatives --config java
sudo update-alternatives --config javac

3.将下面内容添加至vim ~/.bashrc环境变量最后一行

#set java env
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_151
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=${JAVA_HOME}/bin:$PATH

-----------------------------------------------------------------下面内容可以不修改------------------------------------------------------------------------------------------

3.vim ~/.profile
在最后面加入下面内容:

下面格式会乱码,请参考图片

#set java env
export JAVA_HOME = /usr/lib/jvm/java-8-openjdk-amd64 (进去/usr/lib/jvm/下查看,会发现有java-8-openjdk-amd64自动生成)
export JRE_HOME = /usr/lib/jvm/java-8-openjdk-amd64/jre

export PATH = $ JAVA_HOME/bin:$ PATH

export CLASSPATH = .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

-----------------------------------------------------------------------------------------------------------------------------------------------------------

4.source ~/.bashrc

 使环境变量生效,此操作之后可以不用重启电脑。

5.(必须另外打开终端执行$ java -version才会生效)查看配置结果:

$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2~14.04-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

--------------------------------------------------------------------下面内容可以不操作---------------------------------------------------------------------------------------

6.重启电脑:

7.再次查看配置结果:

$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2~14.04-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

----------------------------------------------------------------------------------------------------------------------------------------------------------- 

posted @ 2019-02-16 12:11  演武_zhuwei  阅读(1517)  评论(0编辑  收藏  举报