257

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.

Muhammad Usman
  • 1,220
  • 13
  • 22
Dmitriy Dumanskiy
  • 11,657
  • 9
  • 37
  • 57
  • 1
    What error do you get when you attempt to `sudo apt-get install openjdk-11-jdk`? – Mureinik Sep 25 '18 at 18:45
  • 5
    [Here](https://docs.oracle.com/en/java/javase/11/install/installation-jdk-linux-platforms.html#GUID-ADC9C14A-5F51-4C32-802C-9639A947317F) are the "official" installation instructions for Linux. There's an RPM (`yum`), or you can install manually from archive libraries. But apparently no Debian `apt-get` (yet). Q: So why not just install from tar.gz? See also [update-alternatives](https://stackoverflow.com/questions/12787757/how-to-use-the-command-update-alternatives-config-java) – paulsm4 Sep 25 '18 at 18:49
  • 5
    @Mureinik "E: Unable to locate package openjdk-11-jdk" on Ubuntu 16.04 – Dmitriy Dumanskiy Sep 25 '18 at 18:52
  • @paulsm4 well, apt-get is very convinient, especially when you have dozens of servers :). – Dmitriy Dumanskiy Sep 25 '18 at 18:53
  • 1
    @Mureinik At the moment this package still installs Java 10. It will be updated in the next days I assume to provide Java 11. – Robert Sep 26 '18 at 18:41
  • Check out this question [link](https://askubuntu.com/questions/1037646/why-is-openjdk-10-packaged-as-openjdk-11) – Andra Oct 02 '18 at 01:25
  • 5
    @Robert next days, next weeks, next months... – 9ilsdx 9rvj 0lo Oct 23 '18 at 13:49

12 Answers12

487

Now it is possible to install openjdk-11 this way:

sudo apt-get install openjdk-11-jdk

(Previously it installed openjdk-10, but not anymore)

Joop
  • 3,706
  • 34
  • 55
9ilsdx 9rvj 0lo
  • 7,955
  • 10
  • 38
  • 77
  • 1
    Is this Oracle build or from adoptOpenJDK? – Dmitriy Dumanskiy Nov 13 '18 at 20:22
  • 3
    Actually I think it is the Oracle OpenJDK one. I think Debian/Ubuntu just download the tarball from the Oracle OpenJDK release, add a few patches on top and build their packages. – andresp Dec 14 '18 at 20:09
  • 24
    If you're not using Java in any GUI environment you might prefer installing `openjdk-11-jdk-headless`. Or if all you want is to run something, not compile, `openjdk-11-jre[-headless]` might suit you as well. – Piohen Dec 27 '18 at 17:33
  • 1
    does this include javafx too? – Tharaka Dilshan Dec 09 '19 at 01:08
  • 21
    I had to run `sudo add-apt-repository ppa:openjdk-r/ppa` first to add the repository. – Arboreal Shark May 23 '20 at 21:20
  • 10
    Same here. Also ```sudo apt-get update``` to update the repository. Then ```sudo apt-get install openjdk-11-jdk``` worked. – Michael Jul 01 '20 at 15:20
  • My question: If I already have JDK8 in palce, would it be automatically removed when I install JDK11. – Vipul Tyagi Aug 24 '20 at 08:29
  • @TharakaDilshan JavaFX is not a part of JDK in Java 11. – Line Sep 26 '20 at 20:12
  • If you're trying to perform silent install for example in a Dockerfile, you need an automatic "y" response to prompts: `yes | apt-get install openjdk-11-jdk` – jrbe228 Jan 05 '22 at 16:02
116

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
kaniyan
  • 1,391
  • 1
  • 7
  • 7
93
sudo apt-get install openjdk-11-jdk

after this, try

java -version

to make sure java version is 1.11.x, if found old one or different, check below command to see the available jdks,

update-java-alternatives --list

you should see something like below,

java-1.11.0-openjdk-amd64      1111      /usr/lib/jvm/java-1.11.0-openjdk-amd64 

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

you can see java 1.11 available from above list, use below command to set java 11 to default,

sudo update-alternatives --config java

for above command, you will get something like below and also, will ask for an option to set,

There are 3 choices for the alternative java (providing /usr/bin/java).
   Selection    Path   Priority   Status

 ------------------------------------------------------------   

 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  
 1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode

 *2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081    manual mode 

 3            /usr/lib/jvm/jdk1.8.0_211/bin/java  0         manual mode 

 Press <enter> to keep the current choice[*], or type selection number:

you can select desired selection number, my case it's 0

for javac,

sudo update-alternatives --config javac

will result something like below,

 There are 3 choices for the alternative javac (providing /usr/bin/javac).

 Selection    Path                     Priority  Status

 ------------------------------------------------------------   

 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/javac   1111      auto mode   

 1           /usr/lib/jvm/java-11-openjdk-amd64/bin/javac   1111      manual mode

 *2            /usr/lib/jvm/java-8-openjdk-amd64/bin/javac    1081      manual mode   
 3            /usr/lib/jvm/jdk1.8.0_211/bin/javac        0         manual mode
 
 Press <enter> to keep the current choice[*], or type selection number:

in my case, it's 0 again

after above steps, try

java -version

it will display something like below,

openjdk version "11.0.4" 2019-07-16 

OpenJDK Runtime Environment (build
 11.0.4+11-post-Ubuntu-1ubuntu218.04.3) 

 OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed > mode, sharing)
Mr. 14
  • 9,228
  • 6
  • 37
  • 54
Som
  • 1,467
  • 13
  • 11
51

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
Foreever
  • 7,099
  • 8
  • 53
  • 55
Kamal
  • 1,476
  • 1
  • 13
  • 21
  • 1
    Wow, something even similar to Anaconda for Java? Who'd think! –  May 25 '19 at 00:49
  • error: "Downloaded zip archive corrupt. Are you connected to the internet?" – masterxilo Mar 06 '20 at 11:08
  • 1
    @masterxilo please can you elaborate more on the error you have, for sure you would need internet to download the SDKMAN tool. I have only tried installing the SDKMAN tool on UNIX-Platform are you trying it on the Windows platform? – Kamal Mar 06 '20 at 15:04
  • 1
    yes! sdkman makes life much easier. Super easy install and config, for linux servers, linux docker images, or local machines. Skip the hassle of using a package manager. – TimCO May 19 '21 at 22:24
14

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.

9

First check the default-jdk package, good chance it already provide you an OpenJDK >= 11.
ref: https://packages.ubuntu.com/search?keywords=default-jdk&searchon=names&suite=all&section=all

Ubuntu 18.04 LTS +

So starting from Ubuntu 18.04 LTS it should be ok.

sudo apt update -qq
sudo apt install -yq default-jdk

note: don't forget to set JAVA_HOME

export JAVA_HOME=/usr/lib/jvm/default-java
mvn -version

Ubuntu 16.04 LTS

For Ubuntu 16.04 LTS, only openjdk-8-jdk is provided in the official repos so you need to find it in a ppa:

sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt update -qq
sudo apt install -yq openjdk-11-jdk

note: don't forget to set JAVA_HOME

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
mvn -version
Mizux
  • 8,222
  • 7
  • 32
  • 48
6

I had problems installing open jdk on ubuntu 17.04 I managed to install it using this steps:

wget https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz -O /tmp/openjdk-11+28_linux-x64_bin.tar.gz

tar xfvz /tmp/openjdk-11+28_linux-x64_bin.tar.gz --directory /usr/lib/jvm/

rm /etc/alternatives/java

ln -s /usr/lib/jvm/jdk-11/bin/java /etc/alternatives/java

java -version

You should see this:

openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
Bikesh M
  • 8,163
  • 6
  • 40
  • 52
D.Raluca
  • 101
  • 1
  • 2
4

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
A. Lion
  • 673
  • 5
  • 12
  • 7
    Oracle JVM (Hotspot) is not free anymore for production usage. So I would prefer OpenJDK builds. – Dmitriy Dumanskiy Oct 30 '18 at 12:01
  • 2
    Sadly, I tied this too and it doesn't work. It says E: Unable to locate package oracle-java11-installer – Nditah Nov 06 '18 at 08:04
  • I am getting the following error. How is oracle-java11-installer-local different than oracle-java11-installer? `"$ sudo apt install oracle-java11-installer ..... Package oracle-java11-installer is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source However the following packages replace it: oracle-java11-installer-local E: Package 'oracle-java11-installer' has no installation candidate "` – Bhuvan Jan 24 '23 at 10:59
1

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.

Jose Henriquez
  • 356
  • 2
  • 7
1

Following are command to install openjdk 11

sudo apt-get install openjdk-11-jdk

We can check the version by running following command

java -version

For setting the JAVA_HOME in path we can following command

sudo gedit .bashrc.

Set the following value in bashrc file

export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin

To execute the content of bashrc file run following command

source ~/.bashrc.

0

Just updated older Ubuntu versions to openJDK 11
Actually I need it for Jenkins only and it seems to work fine.

Ubuntu 12.04 (Precise):
Download from openjdk-lts (11.0.4+11-1~12.04) precise
Files:
openjdk-11-jre-headless_11.0.4+11-1~12.04_amd64.deb
openjdk-11-jre_11.0.4+11-1~12.04_amd64.deb

Ubuntu 14.04 (Trusty):
Download from openjdk-lts (11.0.5+10-2ubuntu1~14.04) trusty
Files:
openjdk-11-jre-headless_11.0.5+10-2ubuntu1_14.04_amd64.deb
openjdk-11-jre_11.0.5+10-2ubuntu1_14.04_amd64.deb

Installation
After download I installed the files with Ubuntu Software Center ("headless" first!)
Then I selected the new version with sudo update-alternatives --config java

I didn't have to change any environment variables (like JAVA_HOME) - maybe Jenkins doesn't care about them...

Roman
  • 707
  • 8
  • 16
0

if you want to use official oracle jdk. then download jdk 11 or latest from oracle website: https://www.oracle.com/java/technologies/javase-downloads.html

then use this command to install : sudo dpkg -i the file you downloaded

then add to your PATH using /etc/profile file.

in my case it's just worked 100% using ubuntu 20.04

note: official oracle jdk free only for developments.

swon
  • 1