简体   繁体   中英

Installing Oracle jdk 11 on ubuntu 18.04 LTS

Recently oracle has changed their policy of license. I couldn't install oracle jdk 11 on ubuntu 18.04 LTS. Can anyone please suggest any specific solution for that? thank you

I created a gist to help me address this specific issue: https://gist.github.com/Thoughtscript/d5cdba8013a006dbbd2899e899b95146

Partly reprised below. It took me a while but I got it to work with the OpenJDK-11.0.2 at the jdk.java.net link below.

NOTE It's recommended to download Java 11+ directly from Oracle. It's further recommended to use the OpenJDK 11.0.2 (and avoid other options).
See: https://jdk.java.net/archive/

sudo apt-get update
wget "https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz"
sudo tar -xzvf openjdk-11.0.2_linux-x64_bin.tar.gz
sudo mv jdk-11.0.2 /usr/lib/jvm/

# Config
sudo nano /etc/environment

# Add the line below
# JAVA_HOME="/usr/lib/jvm/jdk-11.0.2/"

# Config
sudo nano ~/.bashrc
# Add the lines below
# JAVA_HOME=/usr/lib/jvm/jdk-11.0.2/
# PATH=$JAVA_HOME/bin:$PATH
source ~/.bashrc

# Verify
echo $JAVA_HOME
javac --version

I'm not sure which JDK you wanted, but here's a couple options:

If you want the closed-source JDK 11, go to the official site and download and install the.deb file .

If you want OpenJDK 11, go to the official site and download the.tar.gz file . Then extract it to a location you want and set the environment variables .

  1. Download the .deb package from Oracle site
  1. install the package by double clicking on it.

  2. Once it is installed set the JAVA_HOME in environment

    sudo nano /etc/environment and add the line JAVA_HOME="/usr/lib/jvm/jdk-11.0.1/"

  3. Add the configuration in .bashrc

sudo nano ~/.bashrc and add following lines

JAVA_HOME=/usr/lib/jvm/jdk-11.0.11/
PATH=$JAVA_HOME/bin:$PATH
  1. refresh the new configuration with source ~/.bashrc

  2. enter he command java-version and you can see the version installed

     OR

Configurations in (step 3 - step 5 )also can be done by using below method as well

Run command

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.11/bin/java 2

sudo update-alternatives --config java

select the desired version from prompt if here are multiple java versions already installed and run following commands

sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-11.0.11/bin/jar 2

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.11/bin/javac 2

sudo update-alternatives --set jar /usr/lib/jvm/jdk-11.0.11/bin/jar

sudo update-alternatives --set javac /usr/lib/jvm/jdk-11.0.11/bin/javac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM