Java Ubuntu 16.04 的 11 安装问题

Java 11 installation problem for Ubuntu 16.04

我已经尝试了所有方法,但不知为何我无法安装 java11。 显示我之前版本的 java

我做了以下步骤:

第 1 步: 我安装了:来自 Oracle 网站的 jdk-11.0.8_linux-x64_bin.deb 文件。

第 2 步: 运行 此命令:sudo dpkg -i jdk-11.0.8_linux-x64_bin.deb

第 3 步:sudo get update

第 4 步: 运行 此命令 sudo vim /etc/profile.d/jdk.sh

第 5 步: 在空文件夹中添加此行:

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

并保存此文件。比我用 ls 检查 usr/lib/jvm 路径 我得到:

default-java@  java-1.8.0-openjdk-amd64@  java-8-openjdk-amd64/  jdk-11.0.8/

然后我输入这个命令:

source /etc/profile.d/jdk.sh

我得到这些输出:

    set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/home/duygu/bin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /home/duygu/bin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/home/duygu/.local/bin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /home/duygu/.local/bin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/usr/local/sbin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /usr/local/sbin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/usr/local/bin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /usr/local/bin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/usr/sbin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /usr/sbin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/usr/bin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /usr/bin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/sbin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /sbin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/bin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /bin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/usr/games may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /usr/games'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/usr/local/games may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /usr/local/games'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/snap/bin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /snap/bin'?
set: Warning: path component /usr/lib/jvm/jdk-11.0.8/bin:/usr/local/jdk-11.0.2/bin may not be valid in PATH.
set: No such file or directory
set: Did you mean 'set PATH $PATH /usr/local/jdk-11.0.2/bin'?

当我检查 java 版本时,我得到:openjdk version "1.8.0_265"

然后输入此命令:update-java-alternatives --list 我得到:

java-1.8.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.8.0-openjdk-amd64

我尝试了 sudo reboot 并再次尝试,但我没有安装 java 11。我该如何安装?我的错在哪里?

已编辑:

我已经尝试过这几行:

sudo add-apt-repository ppa:linuxuprising/java

sudo apt-get update

sudo apt-get install openjdk-11-jdk

我得到这样的错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package openjdk-11-jdk is a virtual package provided by:
  oracle-java15-installer 15-1~linuxuprising3
  oracle-java14-installer 14.0.2-1~linuxuprising1
  oracle-java11-installer-local 11.0.8-1~linuxuprising0
You should explicitly select one to install.

E: Package 'openjdk-11-jdk' has no installation candidate

您可以通过以下命令安装java 11

sudo add-apt-repository ppa:linuxuprising/java

sudo apt-get update

sudo apt-get install openjdk-11-jdk

您可以参考这个 了解如何在 ubuntu.

上安装 openjdk 11

然后你可以运行

update-alternatives --config java

更新java版本。您可以参考此 link 了解如何更新 java 个备选方案。

安装完成后,

sudo nano /etc/environment
JAVA_HOME="/usr/lib/jvm/jdk-11.0.8"

请注意,/bin 不包括在内。保存并退出。那么,

source /etc/environment

顺便说一句,为什么要使正常安装复杂化?