How to install JDK 10 under Ubuntu?

Sam picture Sam · Mar 27, 2018 · Viewed 100.2k times · Source

How do I install Java Development Kit (JDK) 10 on Ubuntu?

The installation instructions on Oracle's help center only explain how to download and extract the archive on Linux platform, without any system setup.

Answer

Sam picture Sam · Mar 27, 2018

Update: JDK 11 Now Available

sudo apt-get install openjdk-11-jdk

For JDK 10

Option 1: Easy Installation (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

Option 2: Manual Installation

  • Download OpenJDK 10 binaries 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


If you prefer Oracle's JDK, download it and follow the installation steps as shown above.