查看是否已安装jdk
以下信息说明未安装
ubuntu@VM-16-6-ubuntu:/var$ java -version
The program 'java' can be found in the following packages:
* default-jre
* gcj-5-jre-headless
* openjdk-8-jre-headless
* gcj-4.8-jre-headless
* gcj-4.9-jre-headless
* openjdk-9-jre-headless
Try: sudo apt install <selected package>
执行以下命令进行安装
ubuntu@VM-16-6-ubuntu:/var$ sudo apt-get install python-software-properties
ubuntu@VM-16-6-ubuntu:/var$ sudo add-apt-repository ppa:webupd8team/java
ubuntu@VM-16-6-ubuntu:/var$ sudo apt-get update
ubuntu@VM-16-6-ubuntu:/var$ sudo apt-get install oracle-java8-installer
最后一个命令会弹出图形化界面,主要是让你接受Jdk License
设置 $JAVA_HOME
- 查看java路径
ubuntu@VM-16-6-ubuntu:~$ sudo update-alternatives --config java
There is 1 choice 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-oracle/jre/bin/java 1081 manual mode
copy上面path路径
/usr/lib/jvm/java-8-oracle/jre/bin/java
- 更新配置
sudo vi /etc/environment
在文件内插入一行
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin/java"
ubuntu@VM-16-6-ubuntu:~$ source /etc/environment
ubuntu@VM-16-6-ubuntu:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle/jre/bin/java
安装完成
网友评论