在Ubuntu 20.04/18.04/16.04以及Debian 9/8上安装Java11

Java 11是2018年发布的一个长期支持的版本,不同于Java 8,在Linux上安装Java 11显得更为复杂点,我这里简单记录下,本文主要来源于这篇 博文

从PPA安装Oracle Java 11 (经测试,在我的Ubuntu 16.04上无法安装,这里也记录下,其他用户可以尝试下,毕竟方便简单)

Ubuntu 20.04

sudo apt update
sudo apt install openjdk-11-jdk

Ubuntu 18.04/16.04

sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java11-set-default

Debian 9/8

echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A
sudo apt update
sudo apt install oracle-java11-set-default

如果不想设置Java 11为默认的Java环境,则安装:

sudo apt install oracle-java11-installer

如果安装成功确认如下:

$ java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

手动安装OpenJDK 11

OpenJDK是一个免费开源的Java环境,下载OpenJDK 11

curl -O https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
tar zxvf openjdk-11.0.2_linux-x64_bin.tar.gz

将生成的文件夹拷贝到/user/local

$ sudo mv jdk-11* /usr/local/

设置环境变量:

$ sudo vim /etc/profile.d/jdk.sh

在里面添加以下内容:

export JAVA_HOME=/usr/local/jdk-11.0.2
export PATH=$PATH:$JAVA_HOME/bin

.bashrc或者.zshrc中添加以下命令:

$ sudo vi ~/.bashrc
## 添加
source /etc/profile.d/jdk.sh

重启或者source /etc/proflie,最后验证安装如下:

$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

$ which java
/usr/local/jdk-11.0.2/bin/java

手动安装Java SE Development Kit 11 (JDK 11)

这里下载最新的JDK 11

curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/11.0.2+9/f51449fcd52f4d52b93a989c5c56ed3c/jdk-11.0.8_linux-x64_bin.deb"

安装:

sudo dpkg -i jdk-11.0.8_linux-x64_bin.deb

中间遇到依赖问题的话,运行:

$ sudo apt -f install
$ sudo dpkg -i jdk-11.0.2_linux-x64_bin.deb

设置环境变量

$ sudo vim /etc/profile.d/jdk.sh
## 添加

export JAVA_HOME=/usr/lib/jvm/jdk-11.0.2/
export PATH=$PATH:$JAVA_HOME/bin

## 激活
$ source /etc/profile.d/jdk.sh
$ java -version
java version "11.0.8" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+9-LTS, mixed mode
Researcher

I am a PhD student of Crop Genetics and Breeding at the Zhejiang University Crop Science Lab. My research interests covers a range of issues:Population Genetics Evolution and Ecotype Divergence Analysis of Oilseed Rape, Genome-wide Association Study (GWAS) of Agronomic Traits.

comments powered by Disqus