How to Install the Jdk on Ubuntu Linux

How to install the JDK on Ubuntu Linux

Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,

How to install Open JDK (Java developement kit) in Ubuntu (Linux)?

  1. Open Terminal from Application Dash or press Ctrl+Alt+T

  2. Update repository:

    sudo add-apt-repository ppa:openjdk-r/ppa  # only Ubuntu 17.4 and earlier
    sudo apt update
  3. Optional: To search available distributions of openjdk, use the following command:

    apt search openjdk
  4. Install the appropriate version with the following command:

    sudo apt install openjdk-8-jdk
    sudo apt install openjdk-8-source #this is optional, the jdk source code
  5. For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path...

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk

    (Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.)

  6. For PATH (Environment Variable) type command as shown below, in Terminal:

    export PATH=$PATH:$JAVA_HOME/bin

  7. To check your installation:

    java -version

How to install JDK 11 under Ubuntu?

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)

How to install the JDK on Ubuntu Linux

Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,

How to install Open JDK (Java developement kit) in Ubuntu (Linux)?

  1. Open Terminal from Application Dash or press Ctrl+Alt+T

  2. Update repository:

    sudo add-apt-repository ppa:openjdk-r/ppa  # only Ubuntu 17.4 and earlier
    sudo apt update
  3. Optional: To search available distributions of openjdk, use the following command:

    apt search openjdk
  4. Install the appropriate version with the following command:

    sudo apt install openjdk-8-jdk
    sudo apt install openjdk-8-source #this is optional, the jdk source code
  5. For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path...

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk

    (Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.)

  6. For PATH (Environment Variable) type command as shown below, in Terminal:

    export PATH=$PATH:$JAVA_HOME/bin

  7. To check your installation:

    java -version

How to install JDK 10 under Ubuntu?

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.

Installing Java 7 on Ubuntu

This answer used to describe how to install Oracle Java 7. This no longer works since Oracle end-of-lifed Java 7 and put the binary downloads for versions with security patches behind a paywall. Also, OpenJDK has grown up and is a more viable alternative nowadays.

In Ubuntu 16.04 and higher, Java 7 is no longer available. Usually you're best off installing Java 8 (or 9) instead.

sudo apt-get install openjdk-8-jre

or, f you also want the compiler, get the jdk:

sudo apt-get install openjdk-8-jdk

In Trusty, the easiest way to install Java 7 currently is to install OpenJDK package:

sudo apt-get install openjdk-7-jre

or, for the jdk:

sudo apt-get install openjdk-7-jdk

If you are specifically looking for Java 7 on a version of Ubuntu that no longer supports it, see https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher .

What's the correct way of installing jdk on linux

You can install and stay up to date with the latest Oracle Java 7 and all you have to do is manually add the PPA repository to the Software Sources.

From http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html:

su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer
exit

For Ubuntu, http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html. With this, I've managed to installed JDK on my ubuntu server.



Related Topics



Leave a reply



Submit