How to install JDK 11 under Ubuntu?

落爺英雄遲暮 提交于 2019-12-02 17:51:40
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
Kamal

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

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

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!