Upgrading Oracle Java

Java Platform, Standard Edition (Java SE) lets you develop and deploy Java applications on desktops and servers, as well as in today’s demanding embedded environments. Java offers the rich user interface, performance, versatility, portability, and security that today’s applications require.

(Current Java version 8u92)

In this tutorial I will show you how to upgrade Java to the latest version available.

If you don’t have Oracle Java installed on your system, you can check out our Install Oracle Java tutorial.

This tutorial is for x64 version and it is the same for x86 but make sure you download x86 if you have 32-bit system.

Packages needed for installation:

  • JDK (Java Development Kit)
    • For Java Developers. Includes a complete JRE plus tools for developing, debugging, and monitoring Java applications.
    • Download from Oracle website
  • JRE (Java Runtime Environment)

Upgrading Oracle Java

Note: This tutorial is based on our Oracle Java Installation tutorial and if you didn’t follow that, you’ll have some additional steps.

1. Download and prepare Java files

Go to links listed above and download packages you need.

After you downloaded Java, you need to copy files to the directory of old Java.

Open Terminal, navigate to your download directory and type:

sudo mv jdk-8u92-linux-x64.tar.gz /usr/local/java

Note: This will copy JDK archive

sudo mv jre-8u92-linux-x64.tar.gz /usr/local/java

Note: This will copy JRE archive

2. Unpack Java files

Go to Java location:

cd /usr/local/java

Run following commands to unpack archives:

For JDK:

sudo tar xvzf jdk-8u92-linux-x64.tar.gz

For JRE:

sudo tar xvzf jre-8u92-linux-x64.tar.gz

Run this to list folder content:

ls -l

You should now have new directories

jdk1.8.0_92
jre1.8.0_92

Along with the old ones.

3. Modify system PATH

We need to modify location for the new Java directories.

To do that, run:

sudo nano /etc/profile

or if you prefer GUI:

sudo gedit /etc/profile

Add following to the end of the file, overwriting existing Java informations:

JAVA_HOME=/usr/local/java/jdk1.8.0_92
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
JRE_HOME=/usr/local/java/jre1.8.0_92
PATH=$PATH:$HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Save and exit file.

4. Inform system

You need to inform your system where your new Java files are located.

Type following commands:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.8.0_92/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_92/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.8.0_92/bin/javaws" 1

Now inform your system that Oracle Java must be default Java:

sudo update-alternatives --set java /usr/local/java/jre1.8.0_92/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_92/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jre1.8.0_92/bin/javaws

And finally you need to reload your /etc/profile to apply changes.

To do that, type:

. /etc/profile

After that, reboot your system.

5. Test your new Java installation

Open Terminal and type this to test your Java version:

java -version

You should get this:

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

Test javac Java Compiler:

javac -version

You should get this output:

javac 1.8.0_92

6. Cleaning up after installation

Go to Java directory:

cd /usr/local/java

Run following commands to remove downloaded files:

sudo rm jdk-8u92-linux-x64.tar.gz
sudo rm jre-8u92-linux-x64.tar.gz

And run this to remove directories of previous Java version:

sudo rm -rf jdk1.8.0_XX
sudo rm -rf jre1.8.0_XX

The latest Java version installation is completed.

Your system should be now configured for developing and running Java applications.

Leave a Reply

Your email address will not be published.