1. 安装默认JRE/JDK
- 更新
sudo apt-get update
- 检查是否安装了Java
java -version
- 如果返回
The program java can be found in the following packages
,说明电脑上并没有安装Java,请执行:
sudo apt-get install default-jre
- 这将会安装JRE(Java Runtime Environment),如果需要安装JDK(Java Development Kit)的话,请执行:
sudo apt-get install default-jdk
安装Oracle JDK
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
安装oracle-java8-installer
sudo apt-get install oracle-java8-installer
Setting the "JAVA_HOME"
sudo update-alternatives --config java
- 返回结果如下:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
* 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number:
含义:
/usr/lib/jvm/java-8-oracle
/usr/lib/jvm/java-8-openjdk-amd64
/usr/lib/jvm/java-8-oracle
- 复制路径信息,并修改
/etc/environment
文件:
sudo gedit /etc/environment
- 在最后一行添加:
JAVA_HOME="YOUR_PATH"
- 然后执行:
source /etc/environment
- 测试
echo $JAVA_HOME