Mark Lucernas
Aug 08, 2020

Installation

OpenJDK

Linux

Ubuntu

Update apt repository

sudo apt update

Install default Java JDK and JRE

sudo apt install default-jdk
sudo apt install default-jre

or install specific JDK or JRE version

sudo apt install openjdk-11-jdk
sudo apt install openjdk-11-jre

Setting default Java version

sudo update-alternatives --config java

Ref:

Oracle

Oracle Java SE downloads links

Windows

Oracle JDK 8

Downloads both Java SE 8 JDK and JRE for Windows (make sure to download .exe)

NOTE: Java SE JDK 8 automatically installs JRE along with it.

Then watch this video for installation. Skip the path variable configuration for a better way of adding default Java JDK version below.

Finally, set the JAVA_HOME and JRE_HOME system environment variables

Better way of adding default JDK version to Windows system variables

Switching JAVA_HOME in Windows

Sample code to switch JAVA_HOME to jdk 8

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_261
set PATH=%JAVA_HOME%\bin;%PATH%

Linux

Ubuntu

Oracle JDK 8

First, download latest Java SE 8 Linux Debian Package or Linux x64 Compressed Archive

Then run the following

NOTE:

  • The 108 at the end of update-aternatives --install is the priority. You can change the value however you like
# for Debian package
sudo dpkg -i jdk-8*_linux-x64_bin.deb
# for Compressed archive
sudo mkdir -p /usr/lib/jvm/
sudo tar xfv jdk-8*-linux-x64.tar.gz -C /usr/lib/jvm/

# install java and javac
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_261/bin/java 108
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_261/bin/javac 108

To remove the path to change priority, use --remove flag then reinstall path

Verify Update Alternatives

sudo update-alternatives --display java

To change alternative mode

sudo update-alternatives --config java

Setup JAVA_HOME and JRE_HOME

sudo  nano /etc/environment

# Then paste the following

JAVA_HOME=/usr/lib/jvm/jdk1.8.0_251/bin
JRE_HOME=/usr/lib/jvm/jdk1.8.0_251/jre

# Source environment
source /etc/environment

# Update
sudo apt-get update

Ref:

Oracle JDK 11 and Higher

First, download the latest Java SE Linux Debian Package Linux x64 Compressed Archive

Then run the following command.

NOTE:

  • Make sure too set the correct downloaded jdk version and replace .X.X's from the command below
  • The 111 at the end of update-aternatives --install is the priority. You can change the value however you like

to remove the path to change priority, use --remove flag then reinstall path.

# For Debian package
sudo dpkg -i jdk-11.X.X_linux-x64_bin.deb
# For Compressed archive
sudo mkdir -p /usr/lib/jvm/
sudo tar xfv jdk-11*-linux-x64.tar.gz -C /usr/lib/jvm/

# Insatll java and javac
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.X.X/bin/java 111
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.X.X/bin/javac 111

Verify Update Alternatives

sudo update-alternatives --display java

To change alternative mode

sudo update-alternatives --config java

Setup JAVA_HOME and JRE_HOME

sudo  nano /etc/environment

# Then paste the following

JAVA_HOME=/usr/lib/jvm/jdk-11.0.7/bin
JRE_HOME=/usr/lib/jvm/jdk-11.0.7/jre

# Source environment
source /etc/environment

# Update
sudo apt-get update

Ref:


Resources