This document is intended to assist you in updating many new release versions of Oracle Java JDK / JRE on Ubuntu Linux. Occasionally, due to bug fixes and security issues, Oracle releases updates for the Java JDK / JRE version.
-
Note:
this article assumes you have a 32-bit or 64-bit version of Oracle Java 7 located at / usr / local / java and you want to upgrade to a new version of Oracle Java.
When you update Java, you also need to update the Java links in your web browser.
Steps
Step 1. Download the new Java binaries
Make sure you select the correct Java JDK / JRE binary files, updated, for your Ubuntu Linux system architecture, 32 or 64 bit, ending in “tar. gz as:
- jdk-7u40-linux-i586.tar.gz (32 bit)
- jre-7u40-linux-i586.tar.gz (32 bit)
- or
- jdk-7u40-linux-x64.tar.gz (64 bit)
- jre-7u40-linux-x64.tar.gz (64 bit)
Method 1 of 4: Instructions for 32-bit Java
Step 1. Become the root user and copy the new compressed binaries from our download directory / 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
Step 2. Now we are going to unpack our new version of Java binary files in the / usr / local / java directory:
- Type / Copy / Paste: sudo tar xvzf jdk-7u40-linux-i586.tar.gz
- Type / Copy / Paste: sudo tar xvzf jre-7u40-linux-i586.tar.gz
Method 2 of 4: 64-bit Java instructions
Step 1. Become the root user and copy the new compressed binaries from our download directory / 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
Step 2. Now we are going to unpack our new version of Java binary files in the / usr / local / java directory:
- Type / Copy / Paste: sudo tar xvzf jdk-7u40-linux-x64.tar.gz
- Type / Copy / Paste: sudo tar xvzf jre-7u40-linux-x64.tar.gz
Step 3. At this point, you should have two new uncompressed binary directories in / usr / local / java for Java JDK / JRE listed as:
jdk1.7.0_40
jre1.7.0_40
with:
jdk1.7.0_25
jre1.7.0_25
Method 3 of 4: Change the Linux System PATH
Step 1. Change the path to the / etc / profile system files, adding the following system variables to them
Use Gedit, Nano or any other text editor, as root, and open / etc / profile.
- Type / Copy / Paste: sudo gedit / etc / profile
- or
- Type / Copy / Paste: sudo nano / etc / profile
Step 2. Scroll down using the arrow keys to go to the end of the file and add the following lines at the bottom of the / etc / profile file in Ubuntu Linux
At this point, to change the Java version numbers from old to new, go to the following system path of the / etc / profile file:
Edit 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 it 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.
Method 4 of 4: Notify the System of the Updated Version of Oracle Java
Step 1. Inform the Ubuntu Linux system where the Oracle Java JRE / JDK file is located
You will now update the system to use Java version 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
Step 2. Specify to Ubuntu that JRE 1.7.0_40 should be the default:
-
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
Step 3. Reload the / etc / profile file into the system path by typing the following command:
-
Type / Copy / Paste:
. / etc / profile
- Note that the extended path to the / etc / profile file will reload after rebooting the Ubuntu system.
Step 4. Check to see if the new version of Java has been successfully installed on your system by running the following commands and checking the version number of the new Java update:
-
Type / Copy / Paste:
java -version
This command displays the version of Java running on the system
Step 5. You should receive a message like this:
-
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 tells you that you are now able to compile Java programs from the terminal.
You should receive a message like this:
- javac 1.7.0_40
Step 6. Later, you will have the option to remove the old Java JDK / JRE version, simply by removing the directories that contain the related old 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
Step 7. Restart Ubuntu Linux and the system will be fully configured to run and develop Java programs
Optional: How to Enable Java in Your Web Browser
To activate Java plugins in your web browser, you need to make a symbolic link from the browser plugins directory to the location of the Java plugins included in your specific software distribution
Google Chrome
Instructions for 32-bit Java
-
Run the commands below.
-
Type / Copy / Paste:
sudo mkdir -p / opt / google / chrome / plugins
This command will create a directory called / opt / google / chrome / plugins
-
Type / Paste / Copy:
cd / opt / google / chrome / plugins
This command will move you to the Google Chrome plugins directory - make sure you are in this directory before making the symbolic link
-
Type / Paste / Copy:
sudo ln -s /usr/local/java/jre1.7.0_40/lib/i386/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) plugin libjavaplugin_oji to the Google Chrome web browser.
-
64-bit Java instructions
-
Run the commands below.
-
Type / Copy / Paste:
sudo mkdir -p / opt / google / chrome / plugins
This command will create a directory called / opt / google / chrome / plugins
-
Type / Paste / Copy:
cd / opt / google / chrome / plugins
This command will move you to the Google Chrome plugins directory - make sure you are in this directory before making the symbolic link
-
Type / Paste / Copy:
sudo ln -s /usr/local/java/jre1.7.0_40/lib/amd64/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) plugin libjavaplugin_oji to the Google Chrome web browser.
-
Memorandum
-
Note:
Sometimes, when you type the above command, you may get a message that reads:
- ln: creating symbolic link `./libnpjp2.so ': File exists
- To correct this problem, 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 running the command.
-
Restart the web browser and go to Java Tester to test if Java works in the web browser.
Mozilla Firefox
Instructions for 32-bit Java
-
Type the following command:
-
Type / Paste / Copy:
cd / usr / lib / mozilla / plugins
This command will move you to the / usr / lib / mozilla / plugins directory - create this directory if you don't already have it
-
Type / Paste / Copy:
sudo mkdir -p / usr / lib / mozilla / plugins
This command will create the / usr / lib / mozilla / plugins directory - make sure you are inside this directory before symbolic linking
-
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 libjavaplugin_oji to the Mozilla Firefox web browser.
-
64-bit Java instructions
-
Run the commands below.
-
Type / Paste / Copy:
cd / usr / lib / mozilla / plugins
This command will move you to the / usr / lib / mozilla / plugins directory - create this directory if you don't already have it
-
Type / Paste / Copy:
sudo mkdir -p / usr / lib / mozilla / plugins
This command will create the / usr / lib / mozilla / plugins directory - make sure you are inside this directory before symbolic linking
-
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 libjavaplugin_oji to the Mozilla Firefox web browser.
-
Memorandum
-
Note:
Sometimes, when you type the above command, you may get a message that reads:
- ln: creating symbolic link `./libnpjp2.so ': File exists
- To correct this problem, 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 running the command.
-
Restart the web browser and go to Java Tester to test if Java works in the web browser.
-