1.安裝jdk命令:
sudo -E add-apt-repository ppa:openjdk-r/ppa -y
sudo -E apt-get update
sudo -E apt-get install openjdk-8-jdkjava
2.完成之後,使用如下命令配置如下java和javac
sudo update-alternatives --config java
sudo update-alternatives --config javacvim
3.將下面內容添加至vim ~/.bashrc環境變量最後一行bash
#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:$PATHjvm
-----------------------------------------------------------------下面內容能夠不修改------------------------------------------------------------------------------------------ui
3.vim ~/.profile
在最後面加入下面內容:spa
下面格式會亂碼,請參考圖片blog
#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:$ PATHget
export CLASSPATH = .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarit
-----------------------------------------------------------------------------------------------------------------------------------------------------------
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)
-----------------------------------------------------------------------------------------------------------------------------------------------------------