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
JAVA_HOME=/usr/local/java/DIR_NAMEPATH=$PATH:$JAVA_HOME/binexport JAVA_HOMEexport 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
and it’s done!
If everything went out correctly you should be able to run
and see your current installed Java version!