问题
So Java 11 is out. Does anybody know how to install it (OpenJDK from Oracle) from the command line?
I would like to see something like it was before for Oracle Java 10:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
P. S. In the similar question proposed instruction:
sudo apt-get install openjdk-11-jdk
doesn't work.
回答1:
sudo apt-get install openjdk-11-jdk
do work, only it installs OpenJDK 10 (very intuitive, isn't it).
This package, sometimes, in undefined future, will became OpenJDK 11 (at least it's speculated to).
If you want to install OpenJDK 11, you need first to add OpenJDK's PPA, and then install the package:
sudo add-apt-repository ppa:openjdk-r/ppa \
&& sudo apt-get update -q \
&& sudo apt install -y openjdk-11-jdk
回答2:
For anyone running a JDK on Ubuntu and want to upgrade to JDK11, I'd recommend installing via sdkman. SDKMAN is a tool for switching JVMs, removing and upgrading.
SDKMAN is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates.
Install SDKMAN
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
$ sdk version
Install Java (11.0.3-zulu)
$ sdk install java
回答3:
To install Openjdk 11 in Ubuntu, the following commands worked well.
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt install openjdk-11-jdk
回答4:
In Ubuntu, you can simply install Open JDK by following commands.
sudo apt-get update
sudo apt-get install default-jdk
You can check the java version by following the command.
java -version
If you want to install Oracle JDK 8 follow the below commands.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
If you want to switch java versions you can try below methods.
vi ~/.bashrc
and add the following line export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221
(path/jdk folder)
or
sudo vi /etc/profile
and add the following lines
#JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
export JRE_HOME
export PATH
You can comment on the other version. This needs to sign out and sign back in to use. If you want to try it on the go you can type the below command in the same terminal. It'll only update the java version for a particular terminal.
source /etc/profile
You can always check the java version by java -version
command.
回答5:
I created a Bash script that basically automates the manual installation described in the linked similar question. It requires the tar.gz
file as well as its SHA256 sum value. You can find out more info and download the script from my GitHub project page. It is provided under MIT license.
回答6:
I came here looking for the answer and since no one put the command for the oracle Java 11 but only openjava 11 I figured out how to do it on Ubuntu, the syntax is as following:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java11-installer
回答7:
We don't need any PPA.. Period ! Get direct, original and official copy of your oracle java straight from oracle. Follow these simple steps.
Step1: Go to this official link for java 11. - https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
Step2: Select radio - Accept License Agreement.
Step3: Click jdk-11.0.x_linux-x64_bin.deb to download. Here "x" is the update version. If you are not a registered user with Oracle, to download this file, you might be asked to logint/register (it doesnt harm).
Step4: Install your downloaded .deb file using command line (sudo dpkg -i /path/to/deb/file/jdk-11.0.x_linux-x64_bin.deb) or any gui tool (gdebi etc.). By default the .deb will be installed at this location - /usr/lib/jvm/jdk-11.0.x (x is your downloaded version).
Step5: Open a new terminal. Run these comands (tweak is as per your version):
cd /usr/lib/jvm/jdk-11.0.x
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-11.0.5/bin/java" 0
exit
Step6: To verify, open a new terminal and issue
java -version
You should get the output (similar to this):
java version "11.0.5" 2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)
You are all set..!!
Later you can add JAVA_HOME=/usr/lib/jvm/jdk-11.0.5/ to your .bashrc file.
来源:https://stackoverflow.com/questions/52504825/how-to-install-jdk-11-under-ubuntu