Friday, January 23, 2015

Upgrading Oracle JDK 8 on Linux Mint 17.1

It was interesting to note that Oracle has just issued updates to their Java. What was NOT interesting to note, however, they STILL have not updated their documentations on HOW, exactly, does one goes about upgrading their present Java installation to their latest version. All I could find was instructions on INSTALLING their Java package and I searched their documentation very closely. Maybe I missed something but I swear that this is unbecoming of a major software vendor. What is wrong (and how much effort will it take) with issuing a simple note on how to upgrade their existing installation?

This article is specifically written to overcome the shortcoming of Oracle, and is targeted towards the Linux Mint 17.1 (Rebecca) users of Oracle Java SE (or JDK) 8. It was written for users of Oracle JDK 8 Update 25 who wants to upgrade to Oracle JDK 8 Update 31 - the 64 bit version. With a little tweaking, it can also be used to update other flavors of Linux. A separate forthcoming article will be written for the Windows platforms.

I will assume that the user has installed Oracle's JDK 8 by following the instructions in my previous blog, which can be found here.

STEP 1: Point your web browser to Oracle's download site here and download the following files:

  jdk-8u31-linux-x64.tar.gz
  jdk-8u31-linux-x64-demos.tar.gz
  jdk-8u31-docs-all.zip

STEP 2: Open a terminal and execute the following commands:

  cd Downloads
  tar xzvf jdk-8u31-linux-x64.tar.gz
  tar xzvf jdk-8u31-linux-x64-demos.tar.gz
  unzip jdk-8u31-docs-all.zip -d jdk1.8.0_31
  sudo mv jdk1.8.0_31/ /usr/lib/jvm/
  sudo chown -R root:root /usr/lib/jvm/jdk1.8.0_31
  cd ~

STEP 3: While still in the terminal, execute the following commands:

  sudo update-alternatives --remove java /usr/lib/jvm/jdk1.8.0_25/bin/java
  sudo update-alternatives --remove javac /usr/lib/jvm/jdk1.8.0_25/bin/javac
  sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_31/bin/java" 1500 --slave "/usr/share/man/man1/java.1" "java.1" "/usr/lib/jvm/jdk1.8.0_31/man/man1/java.1"
  sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_31/bin/javac" 1500 --slave "/usr/share/man/man1/javac.1" "javac.1" "/usr/lib/jvm/jdk1.8.0_31/man/man1/javac.1"

STEP 4: Edit the system-wide profile file by executing:

  sudo nano /etc/profile

Then modify the following lines in the file:

  export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_31

Then save the file, exit the editor, close the terminal and either restart the PC or log off and log in again.

STEP 5: Test the updates by opening a terminal and executing the following:

  java -version
  echo $JAVA_HOME

If the output contains the string "1.8.0_31", then the update was successful.

That's it - you are now using the updated Java. Happy computing!



EDIT: This blog was edited to use the 'update-alternatives' command with 1500 as the 'priority' option in order to set the system to use Oracle's Java automatically. Because of this change, the 'update-alternatives --set' commands were removed.

Strictly speaking, it is not necessary to set the PATH environment variable to include the Java bin directory in order to execute the 'javac' command, but I leave this to user to decide. No harm will come to the system if you do this. The rest of the blog remains unchanged.

Take note that there are more Oracle Java commands that can be set by using 'update-alternatives', but the minimum required by Android Studio is given in this blog. For those who wants to set up a Oracle Java programming environment, read my blog here.



No comments:

Post a Comment