DEV Community

Cover image for Install Oracle Java JDK in Ubuntu Linux

Posted on • Originally published at

Install Oracle Java JDK in Ubuntu Linux

Oracle Java SE 13 was released September 2019. The latest update of Java JDK is 13.0.2. In this post we install the JDK in Ubuntu Linux 18.04 LTS.

# Remove the OpenJDK/JRE completely 
$ sudo apt-get purge openjdk-\* 

$ sudo mkdir -p /usr/local/java 

# Download the Oracle Java JDK for Linux.
$ wget --no-check-certificate -c --header  "Cookie: oraclelicense=accept-securebackup-cookie" ""

$ sudo cp -r jdk-13.0.2_linux-x64_bin.tar.gz /usr/local/java/

$ cd /usr/local/java

# Unpack the compressed Java binaries
$ sudo tar xvzf jdk-13.0.2_linux-x64_bin.tar.gz

# Edit the system PATH file /etc/profile and add the following system variables to your system path.
$ sudo vim /etc/profile

export JAVA_HOME
export JRE_HOME
export PATH

# Inform Ubuntu Linux system where your Oracle Java JDK/JRE is located.
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-13.0.2/bin/java" 1

$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-13.0.2/bin/javac" 1

# Inform Ubuntu Linux system that Oracle Java JDK/JRE must be the default Java.
$ sudo update-alternatives --set java /usr/local/java/jdk-13.0.2/jre/bin/java

$ sudo update-alternatives --set javac /usr/local/java/jdk-13.0.2/bin/javac

#Reload the system PATH  
$ . /etc/profile

# Test to see if Oracle Java is installed correctly
$ java -version

Enter fullscreen mode Exit fullscreen mode

Update: To download Java JDK 14 use the below command

$ wget --no-check-certificate -c --header  "Cookie: oraclelicense=accept-securebackup-cookie" ""
Enter fullscreen mode Exit fullscreen mode

Top comments (0)