Install Oracle Java JDK on Linux


In this post we will find out how to install the official Oracle Java JDK on Linux.

First, you need to download the correct package for your operating system.
Go here and download the Linux .tar.gz file for x86 or x64 platform.

At the time of writing this article, the current available version is Java SE Development Kit 8u74.

Now, copy the file you just downloaded to the folder /usr/local/java by doing

sudo cp -r FILE_NAME /usr/local/java/

Now unpack the archive using this command

sudo tar xvzf FILE_NAME

Wait for the extraction to be completed, then remove the .tar.gz archive.

Now, to let the JDK folder be system-wide available, we need to add it to the PATH. To do this, let’s run this command

sudo gedit /etc/profile

and at the end of the file past these lines

export JAVA_HOME
export PATH

where DIR_NAME is the name of the directory which was created when you extracted the .tar.gz archive.

Now let’s reload our changes by running

source /etc/profile

and it’s done!

If everything went out correctly you should be able to run

java -version

and see your current installed Java version!

Happy development!