This document is intended to assist with the upgrade of the many new release versions of Oracle Java JDK/JRE on Ubuntu Linux. Every so often, due to bug fixes and security issues Oracle releases updates to their version of the Java JDK/JRE.

  • Note: This article presumes you have a version of Oracle Java 7 either 32-bit or 64-bit located in /usr/local/java and you want to upgrade to a new version of Oracle Java. If you don't please see the following article for more information:
  • How to Install Oracle Java on Ubuntu Linux
Method 1
Method 1 of 4:

32-bit Oracle Java instructions:

  1. 1
    Become root user and copy the new compressed Oracle Java binaries from our download directory to /usr/local/java
    • Type/Copy/Paste: cd /home/"your_user_name"/Downloads
    • Type/Copy/Paste: sudo cp -r jdk-7u40-linux-i586.tar.gz /usr/local/java
    • Type/Copy/Paste: sudo cp -r jre-7u40-linux-i586.tar.gz /usr/local/java
    • Type/Copy/Paste: cd /usr/local/java
  2. 2
    Next we are going to unpack our new version of Oracle Java binaries, in the directory /usr/local/java
    • Type/Copy/Paste: sudo tar xvzf jdk-7u40-linux-i586.tar.gz
    • Type/Copy/Paste: sudo tar xvzf jre-7u40-linux-i586.tar.gz
  3. Advertisement
Method 2
Method 2 of 4:

64-bit Oracle Java instructions:

  1. 1
    Become root user and copy the new compressed Oracle Java binaries from our download directory to /usr/local/java
    • Type/Copy/Paste: cd /home/"your_user_name"/Downloads
    • Type/Copy/Paste: sudo -s cp -r jdk-7u40-linux-x64.tar.gz /usr/local/java
    • Type/Copy/Paste: sudo -s cp -r jre-7u40-linux-x64.tar.gz /usr/local/java
    • Type/Copy/Paste: cd /usr/local/java
  2. 2
    Next we are going to unpack our new version of Oracle Java binaries, in the directory /usr/local/java
    • Type/Copy/Paste: sudo tar xvzf jdk-7u40-linux-x64.tar.gz
    • Type/Copy/Paste: sudo tar xvzf jre-7u40-linux-x64.tar.gz
  3. 3
    At this point you should have two new uncompressed binary directories in /usr/local/java for the Java JDK/JRE listed as:

    jdk1.7.0_40
    jre1.7.0_40

    Along with:

    jdk1.7.0_25
    jre1.7.0_25
  4. Advertisement
Method 3
Method 3 of 4:

Modify your Linux system PATH:

  1. 1
    Edit the system PATH file /etc/profile and add the following system variables to your system path. Use gedit, nano or any other text editor, as root, and open up /etc/profile
    • Type/Copy/Paste: sudo gedit /etc/profile
      or
    • Type/Copy/Paste: sudo nano /etc/profile
  2. 2
    Scroll down using your arrow keys to the end of the file and add the following lines below to the end of your /etc/profile file in Ubuntu Linux,at this point you are going to be changing the version numbers from the old Oracle Java to the new version of Java, you will change the versions numbers in the following system PATH file /etc/profile:

    Modify the /etc/profile file:
    JAVA_HOME=/usr/local/java/jdk1.7.0_25
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    JRE_HOME=/usr/local/java/jre1.7.0_25
    PATH=$PATH:$HOME/bin:$JRE_HOME/bin
    export JAVA_HOME
    export JRE_HOME
    export PATH

    Change to this:
    JAVA_HOME=/usr/local/java/jdk1.7.0_40
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    JRE_HOME=/usr/local/java/jre1.7.0_40
    PATH=$PATH:$HOME/bin:$JRE_HOME/bin
    export JAVA_HOME
    export JRE_HOME
    export PATH

    Save the file and exit
  3. Advertisement
Method 4
Method 4 of 4:

Inform your system of the updated Oracle Java version:

  1. 1
    Inform your Ubuntu Linux system where your Oracle Java JRE/JDK is located, now you will want to update the system to use Oracle Java 1.7.0_40
    • Type/Copy/Paste: sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_40/bin/java" 1
    • Type/Copy/Paste: sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_40/bin/javac" 1
    • Type/Copy/Paste: sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_40/bin/javaws" 1
  2. 2
    Inform your Ubuntu Linux system, that Oracle Java JRE 1.7.0_40 must be the new default Java
    • Type/Copy/Paste: sudo update-alternatives --set java /usr/local/java/jre1.7.0_40/bin/java
    • Type/Copy/Paste: sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_40/bin/javac
    • Type/Copy/Paste: sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_40/bin/javaws
  3. 3
    Reload your system wide PATH /etc/profile by typing the following command:
    • Type/Copy/Paste: . /etc/profile
    • Note your system wide PATH /etc/profile file will reload after reboot of your Ubuntu Linux system
  4. 4
    Test to see if the new version of Oracle Java was installed correctly on your system by running the following commands and noting the version number of the new Java update.
    • Type/Copy/Paste: java -version
      • this command displays the version of Java running on your system
  5. 5
    You should receive a message which displays:
    • java version "1.7.0_40"

      Java(TM) SE Runtime Environment (build 1.7.0_40-b08)Java HotSpot(TM) 64-Bit Server VM (build build 25.1-b02, mixed mode)
    • Type/Copy/Paste: javac -version
    • this command lets you know that you are now able to compile java programs from the terminal
      • You should receive a message which displays:
    • javac 1.7.0_40
  6. 6
    Afterwards, you have the option of removing the old Oracle Java JDK/JRE, by simply removing the directory's which hold the old Java JDK/JRE binaries.
    • Type/Copy/Paste: cd /usr/local/java
    • Type/Copy/Paste: sudo rm -rf jdk1.7.0_40
    • Type/Copy/Paste: sudo rm -rf jre1.7.0_40
  7. 7
    Reboot your Ubuntu Linux system and your system will be fully configured for running and developing Java programs.
  8. Advertisement

Optional: How to enable Oracle Java in your Web Browsers

  1. To enable your Java plug-in in your web browsers you must make a symbolic link from the web browsers plug-in directory to the location of the Java plug-in included in your distribution of Oracle Java.

Google Chrome

32-bit Oracle Java instructions:

  1. Issue the following commands.
    • Type/Copy/Paste: sudo mkdir -p /opt/google/chrome/plugins
      • this will create a directory called /opt/google/chrome/plugins
    • Type/Paste/Copy: cd /opt/google/chrome/plugins
      • this will change you into the google chrome plugins directory,make sure you are in this directory before you make the symbolic link
    • Type/Paste/Copy: sudo ln -s /usr/local/java/jre1.7.0_40/lib/i386/libnpjp2.so
      • this will create a symbolic link from the Java JRE( Java Runtime Environment ) plugin libnpjp2.so to your Google Chrome web browser

64-bit Oracle Java instructions:

  1. Issue the following commands.
    • Type/Copy/Paste: sudo mkdir -p /opt/google/chrome/plugins
      • this will create a directory called /opt/google/chrome/plugins
    • Type/Paste/Copy: cd /opt/google/chrome/plugins
      • this will change you into the google chrome plugins directory,make sure you are in this directory before you make the symbolic link
    • Type/Paste/Copy: sudo ln -s /usr/local/java/jre1.7.0_40/lib/amd64/libnpjp2.so
      • this will create a symbolic link from the Java JRE( Java Runtime Environment ) plugin libnpjp2.so to your Google Chrome web browser

Reminders:

  1. Note: Sometimes when you issue the above command you may receive a message which states:
    • ln: creating symbolic link `./libnpjp2.so': File exists
    • To correct this issue simply remove the previous symbolic link using the following command:
    • Type/Copy/Paste: cd /opt/google/chrome/plugins
    • Type/Copy/Paste: sudo rm -rf libnpjp2.so
    • Make sure you are in the /opt/google/chrome/plugins directory before you issue the command
  2. Restart your web browser and go to Java Tester to test if Java is functioning in your web browser.

Mozilla Firefox

32-bit Oracle Java instructions:

  1. Issue the following command
    • Type/Paste/Copy: cd /usr/lib/mozilla/plugins
      • this will change you into the directory /usr/lib/mozilla/plugins, create this directory if you do not have it
    • Type/Paste/Copy: sudo mkdir -p /usr/lib/mozilla/plugins
      • this will create the directory /usr/lib/mozilla/plugins, make sure you are in this directory before you make the symbolic link
    • Type/Paste/Copy: sudo ln -s /usr/local/java/jre1.7.0_40/lib/i386/libnpjp2.so
      • this will create a symbolic link from the Java JRE( Java Runtime Environment ) plugin libnpjp2.so to your Mozilla Firefox web browser

64-bit Oracle Java instructions:

  1. Issue the following commands.
    • Type/Paste/Copy: cd /usr/lib/mozilla/plugins
      • this will change you into the directory /usr/lib/mozilla/plugins, create this directory if you do not have it
    • Type/Paste/Copy: sudo mkdir -p /usr/lib/mozilla/plugins
      • this will create the directory /usr/lib/mozilla/plugins, make sure you are in this directory before you make the symbolic link
    • Type/Paste/Copy: sudo ln -s /usr/local/java/jre1.7.0_40/lib/amd64/libnpjp2.so
      • this will create a symbolic link from the Java JRE( Java Runtime Environment ) plugin libnpjp2.so to your Mozilla Firefox web browser

Reminders:

  1. Note: Sometimes when you issue the above command you may receive a message which states:
    • ln: creating symbolic link `./libnpjp2.so': File exists
    • To correct this issue simply remove the previous symbolic link using the following command:
    • Type/Copy/Paste: cd /usr/lib/mozilla/plugins
    • Type/Copy/Paste: sudo rm -rf libnpjp2.so
    • Make sure you are in the /usr/lib/mozilla/plugins directory before you issue the command
  2. Restart your web browser and go to Java Tester to test if Java is functioning in your web browser.

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 13 people, some anonymous, worked to edit and improve it over time. This article has been viewed 296,175 times.
How helpful is this?
Co-authors: 13
Updated: February 3, 2021
Views: 296,175
Categories: Ubuntu
Advertisement