Java is a programming language having almost similar syntax to C++, intended to have minimum dependencies and let the developer write once, run anywhere (WORA)

Java Development Kit (JDK) is needed by developer to compile a Java program and to be executed with Java Runtime Environment (JRE) installed on top of OS.

Ubuntu provides multiple OpenJDK's Java Development Kit in their default apt repository that you can choose to install. There's a default JDK version set for each Ubuntu version, and you can also install multiple JDKs on your system if required.

Steps to install Java Development Kit (JDK) on Ubuntu:

  1. Launch terminal.
  2. Fetch the latest package list.
    $ sudo apt update
  3. Install the desired version of OpenJDK JDK.
    user@ubuntu-host:~$ sudo apt install default-jdk --assume-yes
    [sudo] password for user: 
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    The following additional packages will be installed:
      default-jdk-headless libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev
      libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless x11proto-dev xorg-sgml-doctools
      xtrans-dev
    Suggested packages:
      libice-doc libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-11-demo openjdk-11-source visualvm
    The following NEW packages will be installed:
      default-jdk default-jdk-headless libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev
      libxcb1-dev libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless x11proto-dev
      xorg-sgml-doctools xtrans-dev
    0 upgraded, 15 newly installed, 0 to remove and 186 not upgraded.
    Need to get 217 MB of archives.
    ### snipped ###
    update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jstat to provide /usr/bin/jstat (jstat) in auto mode
    update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jstatd to provide /usr/bin/jstatd (jstatd) in auto mode
    update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/rmic to provide /usr/bin/rmic (rmic) in auto mode
    update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/serialver to provide /usr/bin/serialver (serialver) in auto mode
    update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jaotc to provide /usr/bin/jaotc (jaotc) in auto mode
    update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jhsdb to provide /usr/bin/jhsdb (jhsdb) in auto mode
    Setting up libpthread-stubs0-dev:amd64 (0.4-1build2) ...
    Setting up xtrans-dev (1.4.0-1) ...
    Setting up default-jdk-headless (2:1.11-72build2) ...
    Setting up openjdk-11-jdk:amd64 (11.0.16+8-0ubuntu1~22.04) ...
    update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode
    Setting up xorg-sgml-doctools (1:1.11-1.1) ...
    Setting up default-jdk (2:1.11-72build2) ...
    Processing triggers for sgml-base (1.30) ...
    Setting up x11proto-dev (2021.5-1) ...
    Setting up libxau-dev:amd64 (1:1.0.9-1build5) ...
    Setting up libice-dev:amd64 (2:1.0.10-1build2) ...
    Setting up libsm-dev:amd64 (2:1.2.3-1build2) ...
    Processing triggers for man-db (2.10.2-1) ...
    Setting up libxdmcp-dev:amd64 (1:1.1.3-0ubuntu5) ...
    Setting up libxcb1-dev:amd64 (1.14-3ubuntu3) ...
    Setting up libx11-dev:amd64 (2:1.7.5-1) ...
    Setting up libxt-dev:amd64 (1:1.2.1-1) ...
    user@ubuntu-host:~$ 
  4. Check the JDK version to verify the installation.
    user@ubuntu-host:~$ javac --version
    javac 11.0.16
    user@ubuntu-host:~$ 
  5. The default version can be changed if there is multiple versions of JDK was installed.
    $ sudo update-alternatives --config javac 

Discuss the article:

Comment anonymously. Login not required.