Install JDK/JRE for Ubuntu

There are two versions of JDK/JRE can be installed on Ubuntu:

  • Open JDK/JRE
  • Oracle JDK/JRE

Install Open JDK/JRE

Open JDK/JRE can be easily installed by

1
2
sudo apt install default-jre
sudo apt install default-jdk

Install Oracle standalone JRE

  1. First of all download Oracle JRE from Oracle
  2. Unpack downloaded package and install it into the path you like(i.e /usr/lib/java)
    1
    2
    cd /usr/lib/java
    sudo tar -zxvf ~/Downloads/jre-8u231-linux-x64.tar.gz
  3. Add JRE installation path into $PATH
    1
    sudo nano /etc/environment
    Add :/usr/lib/java/jre1.8.0_231 into PATH
  4. Add installed java as alternative
    1
    sudo update-alternatives --install /usr/bin/java java /usr/lib/java/jre1.8.0_231/bin/java 1
    To switch to other alternative java. use:
    1
    sudo update-alternatives --config java
  5. Check installation
    1
    2
    3
    4
    java -version
    java version "1.8.0_231"
    Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)