Java 如何在 Ubuntu 下安装 JDK 10?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49507160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install JDK 10 under Ubuntu?
提问by Wesam
How do I install Java Development Kit (JDK) 10 on Ubuntu?
如何在 Ubuntu 上安装 Java 开发工具包 (JDK) 10?
The installation instructionson Oracle's help center only explain how to download and extract the archive on Linux platform, without any system setup.
Oracle 帮助中心的安装说明只说明了如何在 Linux 平台上下载和解压归档文件,没有进行任何系统设置。
采纳答案by Wesam
Update: JDK 11 Now Available
更新:JDK 11 现已推出
sudo apt-get install openjdk-11-jdk
For JDK 10
对于 JDK 10
Option 1: Easy Installation (PPA)
选项 1:轻松安装 (PPA)
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Then set as default with:
然后设置为默认值:
sudo apt-get install oracle-java10-set-default
And finally verify Installation with:
最后验证安装:
$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Source: Linux Uprising
来源:Linux 起义
Option 2: Manual Installation
选项 2:手动安装
Download OpenJDK 10binaries for Linux.
Untar the downloaded archive:
tar xzvf openjdk-10_linux-x64_bin.tar.gz
Move the extracted archive to where your system keeps your installed JDKs:
sudo mv jdk-10 /usr/lib/jvm/java-10-openjdk-amd64/
Add the new Java alternative:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1
Update your system's java alternatives and choose JDK 10:
$ sudo update-alternatives --config java here are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 auto mode * 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 3 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode Press <enter> to keep the current choice[*], or type selection number:
and
$ sudo update-alternatives --config javac There are 3 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 auto mode 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode 3 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib/jvm/java-10-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
Verify your installation with:
$ java --version openjdk 10 2018-03-20 OpenJDK Runtime Environment 18.3 (build 10+46) OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
and
$ javac --version javac 10
Done
下载适用于 Linux 的OpenJDK 10二进制文件。
解压下载的存档:
tar xzvf openjdk-10_linux-x64_bin.tar.gz
将提取的存档移动到系统保存已安装 JDK 的位置:
sudo mv jdk-10 /usr/lib/jvm/java-10-openjdk-amd64/
添加新的 Java 替代方案:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1
更新系统的 java 替代品并选择 JDK 10:
$ sudo update-alternatives --config java here are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 auto mode * 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 3 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode Press <enter> to keep the current choice[*], or type selection number:
和
$ sudo update-alternatives --config javac There are 3 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 auto mode 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode 3 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib/jvm/java-10-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
使用以下命令验证您的安装:
$ java --version openjdk 10 2018-03-20 OpenJDK Runtime Environment 18.3 (build 10+46) OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
和
$ javac --version javac 10
完毕
If you prefer Oracle's JDK, download itand follow the installation steps as shown above.
如果您更喜欢 Oracle 的 JDK,请下载它并按照上图所示的安装步骤进行操作。
回答by nitnamby
You need to do update-alternatives --install before the final step.
您需要在最后一步之前执行 update-alternatives --install 。
sudo update-alternatives --install "/usr/bin/java" java "/usr/lib/jvm/java-10-openjdk-amd64/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" javac "/usr/lib/jvm/java-10-openjdk-amd64/bin/javac" 1
回答by stalet
There is a ppa on java 10 that installs oracle's java: https://launchpad.net/~linuxuprising/+archive/ubuntu/java
java 10上有一个安装oracle的java的ppa:https: //launchpad.net/~linuxuprising/+archive/ubuntu/java
I am not sure if this will be maintained though. It seems to be a copy of the webupd8 way on how to handle oracle java installation (ref: documentation).
我不确定这是否会得到维护。它似乎是关于如何处理 oracle java 安装的 webupd8 方式的副本(参考:文档)。
How to use this ppa:
如何使用这个ppa:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Verify installation:
验证安装:
$ /usr/lib/jvm/java-10-oracle/bin/java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Setting up environment variables (make java10 default)
设置环境变量(使 java10 默认)
sudo apt-get install oracle-java10-set-default
回答by Uddhav Gautam
Note: You need update-alternatives
only if you have multiple java versions.
注意:仅当您有多个 java 版本时才需要update-alternatives
。
Note: You can purge everything about Java before fresh installing new Java.
注意:您可以在全新安装新 Java 之前清除有关 Java 的所有内容。
sudo apt purge java*
For Java 10 fresh installation
对于 Java 10 全新安装
- Download JDK 10 from here (you can download JRE and server JRE): http://www.oracle.com/technetwork/java/javase/downloads/index.html
Extract and put somewhere in
/opt/java
directory. You putting JDK in/opt/java
directory makes it will be usable for all users as it is being in the public/opt
directory.(Note: I downloaded JDK, JRE, and server JRE, and extracted JDK and renamed extracted the folder to jdk10, extracted JRE and renamed extracted the folder to jre10, and extracted server JRE and renamed extracted the folder to jre10server as shown in below snapshot).
- 从这里下载 JDK 10(您可以下载 JRE 和服务器 JRE):http: //www.oracle.com/technetwork/java/javase/downloads/index.html
提取并放置在
/opt/java
目录中的某个位置。您将 JDK 放在/opt/java
目录中使其对所有用户都可用,因为它位于公共/opt
目录中。(注意:我下载了 JDK、JRE 和服务器 JRE,并解压了 JDK 并重命名了解压文件夹为 jdk10,解压了 JRE 并重命名了解压文件夹为 jre10,解压了服务器 JRE 并重命名了解压文件夹为 jre10server,如下图所示)。
Now, you need to reload the /etc/environment
script file into the system using source command as below.
现在,您需要/etc/environment
使用如下所示的 source 命令将脚本文件重新加载到系统中。
source /etc/environment
If you want to know more about update-alternativesthen here is the link: https://askubuntu.com/questions/159575/how-do-i-make-java-default-to-a-manually-installed-jre-jdk
如果您想了解有关更新替代方案的更多信息,请访问以下链接:https: //askubuntu.com/questions/159575/how-do-i-make-java-default-to-a-manually-installed-jre- jdk
回答by Sanjay-Dev
There are different ways of doing this , but the most convenient and easy way of doing this is i found in a video link.
有不同的方法可以做到这一点,但最方便和最简单的方法是我在视频链接中找到的。
This guy shows how can you install it manually .
这家伙展示了如何手动安装它。
The advantage is you dnt give control to os to install stuff and if you want to switch between JDK versions , you can do that very easily . Steps :-
优点是你不需要控制 os 来安装东西,如果你想在 JDK 版本之间切换,你可以很容易地做到这一点。脚步 :-
Step 1- Download JDK and Extract it
步骤 1- 下载 JDK 并解压
Step 2- Move your extracted folder in a proper directory of your choice.
步骤 2- 将提取的文件夹移动到您选择的正确目录中。
Step 3- Set environment variable as we do in Windows System Update your .bashrc file and add the following line
第 3 步 - 设置环境变量,就像我们在 Windows 系统中所做的那样更新您的 .bashrc 文件并添加以下行
export JAVA_HOME=/usr/lib/java/jdk1.8.0_77
export PATH="$PATH:$JAVA_HOME/bin"
回答by Alexander Mikheev
I've found a repo
我找到了一个回购
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update
sudo apt install openjdk-10-jdk
回答by lealceldeiro
I found sdkmana very useful tool because it provides a convenient way of installing (managing!) what JDK install/usein a given time from the shell.
我发现sdkman是一个非常有用的工具,因为它提供了一种方便的方式来安装(管理!)在给定时间内从 shell安装/使用的JDK 。
For example, once it is installed, you can:
例如,一旦安装,您可以:
- List available JDK (list candidates):
sdk list java
- 列出可用的 JDK(列出候选):
sdk list java
This will show something like:
这将显示如下内容:
==============================================================================
Available Java Versions
==============================================================================
9.0.4-open
+ 8u161-oracle
8.0.191-oracle
> + 8.0.171-oracle
7.0.191-zulu
12.ea.15-open
11.0.1-open
10.0.2-open
1.0.0-rc8-graal
==============================================================================
+ - local version
* - installed
> - currently in use
==============================================================================
- Install a specific version:
sdk install java 10.0.2-open
- 安装特定版本:
sdk install java 10.0.2-open
It will show something like:
它会显示如下内容:
Downloading: java 10.0.2-open
In progress...
################# 12,3%
- Use a specific version:
sdk use java 10.0.2-open
- 使用特定版本:
sdk use java 10.0.2-open
It will show something like:
它会显示如下内容:
Using java version 10.0.2-open in this shell.
Usage
用法
For more info see https://sdkman.io/usage
有关更多信息,请参阅https://sdkman.io/usage