How to install JDK 10 under Ubuntu?
Asked Answered
B

7

75

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.

Bare answered 27/3, 2018 at 7:48 Comment(2)
Hey take a look at: askubuntu.com/questions/56104/… the steps are the same for java 10Kbp
Openjdk 10 may be available in 18.04 coming up shortly. phoronix.com/…Racemose
B
193

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.

Bare answered 27/3, 2018 at 7:48 Comment(10)
It may be a good idea not to use the exact same directory name as the official package may end up using to avoid overwriting files then.Racemose
Maybe you have to install the alternative before. So, before running the command $ sudo update-alternatives --config java Run the command for installing it $ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-10-openjdk-amd64/ <priority> Where <priority> is a number of your choice definning which alternative should runs first, unless you set it mannualyCracked
@Wesam do you know who prepares PPA package for java 10 and estimates for it?Mauriac
@DmitriyDumanskiy WebUpd8 team prepared JDK 8/9 PPA, so they may release one for JDK 10. I don't have an estimate of when or if they will release it, though. You may find JDK 10 PPA repos released by obscure publishers that should not be trusted for the potential security risk involved.Bare
Do not forget the sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-10-openjdk-amd64/bin/jar 1 for the jar command!Carry
"sudo apt-get install openjdk-11-jdk" is that Oracle build or AdoptOpenJDK?Mauriac
Ubuntu package openjdk-11-jdk contains java 10.0.2 :)Dacha
also note that you can't use the ppa for jdk 10 on Ubuntu 18.10 for some reason. Package 'oracle-java10-installer' has no installation candidateLorinalorinda
FYI as of 1/29/2019, on Ubuntu, running apt-get install openjdk-11-jdk actually installs Java 10. Running java -version outputs openjdk version "10.0.2" 2018-07-17 . This is a known issue. Here is the relevant bug report.Gadhelic
The ppa has removed java 10 support (because Oracle removed the download as well), so that part is not an option anymoreBeebread
P
13

I've found SdkMan! a very useful tool because it provides a convenient way for managing your JDKs from the shell.

For example, once it is installed, you can:

Install a specific JDK version: sdk install java 10.0.2-open

Downloading: java 10.0.2-open

In progress...

#################                             12,3%

Use a specific JDK version: sdk use java 10.0.2-open

Using java version 10.0.2-open in this shell.

List available JDK: sdk list java

===================================================================
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
=======================================================================

And much more

See https://sdkman.io/usage

Phyte answered 31/10, 2018 at 12:27 Comment(0)
O
8

There is a ppa on java 10 that installs oracle's java: 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).

How to use this 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)

sudo apt-get install oracle-java10-set-default
Odaodab answered 18/4, 2018 at 10:25 Comment(2)
This PPA has an obscure origin and I would not trust it. We should rather wait for the WebUp8 release.Bare
It's mentioned from the official WebUp8 repo: launchpad.net/~webupd8team/+archive/ubuntu/javaSoothfast
D
3

Note: You need update-alternatives only if you have multiple java versions.

Note: You can purge everything about Java before fresh installing new Java.

 sudo apt purge java*

For Java 10 fresh installation

  1. Download JDK 10 from here (you can download JRE and server JRE): http://www.oracle.com/technetwork/java/javase/downloads/index.html

  2. 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).

  3. Update your /etc/environment file as below enter image description here

Now, you need to reload the /etc/environment script file into the system using source command as below.

source /etc/environment

enter image description here

If you want to know more about update-alternatives then here is the link: https://askubuntu.com/questions/159575/how-do-i-make-java-default-to-a-manually-installed-jre-jdk

Dietrich answered 21/5, 2018 at 15:45 Comment(0)
I
1

You need to do update-alternatives --install before the final step.

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
Inharmonic answered 6/4, 2018 at 10:17 Comment(0)
R
1

I've found a repo

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update
sudo apt install openjdk-10-jdk

Repo home page

Renewal answered 20/9, 2018 at 15:4 Comment(2)
That link will last an internet moment and then it will be dead and this answer to this off-topic question will not be helpful anymore.Lisk
Fully redundand to install openjkd10 (it is contained in openjdk-11-jdk) but necessary if you want real jdk 11.Simms
N
0

Install Jdk 10 On Linux Ubuntu

  1. Download the required tarball from from Oracle official website, i.e. https://www.oracle.com

  2. Unzip this tarball using "tar -zxvf tarball_name”

  3. Create a folder named "java" in "/usr/lib", you need root permission
    sudo mkdir /usr/lib/java

  4. Move the extracted folder to “/usr/lib/java/” by using the following command:
    sudo mv java-10-dir-name/ /usr/lib/java/

  5. Now go to the location, i.e. cd /usr/lib/java/java-10-dir-name/

  6. Next, run these below scripts in terminal:

         sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/java-10-dir-name/bin/java" 1
    
         sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/java-10-dir-name/bin/javac" 1
    
         sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/java-10-dir-name/bin/javaws" 1
     

    NOTE: In the commands given above, you have to name the extracted directory of "java" instead of "java-10-dir-name".

    Update the JAVA_HOME in your ~/.bashrc

         export JAVA_HOME=/usr/lib/java/java-10-dir-name
         set PATH="$PATH:$JAVA_HOME/bin"
         export PATH
     

    Verify the installation

    verify whether Java 10 is installed correctly in your machine, execute the following command in your terminal:

         $ 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
     
Nimrod answered 4/3, 2021 at 8:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.