This article will teach you how to upgrade Oracle Java JDK / JRE on Ubuntu Linux. Oracle releases Java JDK / JRE updates frequently to address bugs and improve security.
-
Attention.
This article assumes that you already have a 32- or 64-bit version of Oracle Java 7 installed located in / usr / local / java and would like to upgrade to the latest versions of Oracle Java. If not, read the following article:
- How to Install Oracle Java on Ubuntu Linux
Steps

Step 1. Download the new Oracle Java binaries
Make sure you select the appropriate binaries for your Ubuntu Linux system (32- or 64-bit) (they have the tar.gz extension):
- 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: Upgrade instructions for a 32-bit system:

1 Log in to the system and copy the downloaded Oracle Java archive binaries from the download folder to / usr / local / java
-
Print / copy / paste.
cd / home /"your_user_name"/ Downloads
-
Print / copy / paste.
sudo cp -r jdk-7u40-linux-i586.tar.gz / usr / local / java
-
Print / copy / paste.
sudo cp -r jre-7u40-linux-i586.tar.gz / usr / local / java
-
Print / copy / paste.
cd / usr / local / java

2 Next, unpack the binaries of the new version into / usr / local / java
-
Print / copy / paste.
sudo tar xvzf jdk-7u40-linux-i586.tar.gz
-
Print / copy / paste.
sudo tar xvzf jre-7u40-linux-i586.tar.gz
Method 2 of 4: Upgrade instructions for a 64-bit system:

1 Log in to the system and copy the downloaded Oracle Java archive binaries from the download folder to / usr / local / java
-
Print / copy / paste.
cd / home /"your_user_name"/ Downloads
-
Print / copy / paste.
sudo -s cp -r jdk-7u40-linux-x64.tar.gz / usr / local / java
-
Print / copy / paste.
sudo -s cp -r jre-7u40-linux-x64.tar.gz / usr / local / java
-
Print / copy / paste.
cd / usr / local / java

2 Next, unpack the binaries of the new version into / usr / local / java
-
Print / copy / paste.
sudo tar xvzf jdk-7u40-linux-x64.tar.gz
-
Print / copy / paste.
sudo tar xvzf jre-7u40-linux-x64.tar.gz
Step 3. At this point, in / usr / local / java, you should have two new folders for Java JDK / JRE called: jdk1.7.0_40
jre1.7.0_40
Together with:
jdk1.7.0_25
jre1.7.0_25

Method 3 of 4: Editing the System File:

Step 1. Edit the system file / etc / profile and add the following system variables
As root, use gedit, nano or any other text editor to open / etc / profile
-
Print / copy / paste.
sudo gedit / etc / profile
- or
-
Print / copy / paste.
sudo nano / etc / profile
Step 2. Go to the end of the / etc / profile file and add the following lines at the very end (you will now change the Oracle Java version numbers from old to new; you do this in the system file / etc / profile)
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 to:
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 close it

Method 4 of 4: Point the system to an updated version of Oracle Java:

Step 1. Point the system to the location of the updated version of Oracle Java JRE / JDK (the system will now switch to Oracle Java 1.7.0_40)
-
Print / copy / paste.
sudo update-alternatives --install "/ usr / bin / java" "java" "/ usr / local / java /jre1.7.0_40/ bin / java "1
-
Print / copy / paste.
sudo update-alternatives --install "/ usr / bin / javac" "javac" "/ usr / local / java /jdk1.7.0_40/ bin / javac "1
-
Print / copy / paste.
sudo update-alternatives --install "/ usr / bin / javaws" "javaws" "/ usr / local / java /jre1.7.0_40 / bin/ javaws "1

Step 2. Tell your system that Oracle Java JRE 1.7.0_40 will be the new default Java version
-
Print / copy / paste.
sudo update-alternatives --set java / usr / local / java /jre1.7.0_40/ bin / java
-
Print / copy / paste.
sudo update-alternatives --set javac / usr / local / java /jdk1.7.0_40/ bin / javac
-
Print / copy / paste.
sudo update-alternatives --set javaws / usr / local / java /jre1.7.0_40/ bin / javaws

Step 3. Reload the system file / etc / profile with the following command
-
Print / copy / paste.
/ etc / profile
- Note that the / etc / profile file will reload after a system reboot.

Step 4. Check the correctness of the installation of the new version of Oracle Java using the following commands (look at the number of the current Java version)
-
Print / copy / paste.
java -version
this command will display on the screen the Java version number that is currently running

Step 5. You will see the following message
-
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)
-
Print / copy / paste.
javac -version
- This command lets you know that you can now compile Java programs in the terminal.
You will see the following message:
- javac 1.7.0_40

Step 6. You can now uninstall the old version of Oracle Java JDK / JRE by deleting the old version file folders
-
Print / copy / paste.
cd / usr / local / java
-
Print / copy / paste.
sudo rm -rf jdk1.7.0_40
-
Print / copy / paste.
sudo rm -rf jre1.7.0_40

Step 7. Reboot the system and it will be ready to work with Java programs
Optional: How to enable Oracle Java in your browser
To enable the Java plugin in your browser, you need to link from the browser plugins folder to the location of the Java plugin included with your Oracle Java distribution
Google chrome
Instructions for a 32-bit system:
- Enter the following commands.
-
Print / copy / paste.
sudo mkdir -p / opt / google / chrome / plugins
This will create a folder / opt / google / chrome / plugins
-
Print / copy / paste.
cd / opt / google / chrome / plugins
This will take you to the google chrome plugins folder; make sure you are in this folder before creating the link
-
Print / copy / paste.
sudo ln -s /usr/local/java/jre1.7.0_40/lib/i386/libnpjp2.so
- This will create a link between Java JRE (Java Runtime Environment) plugin libnpjp2.so and Google Chrome browser
-
Instructions for a 64-bit system:
- Enter the following commands.
-
Print / copy / paste.
sudo mkdir -p / opt / google / chrome / plugins
This will create a folder / opt / google / chrome / plugins
-
Print / copy / paste.
cd / opt / google / chrome / plugins
This will take you to the google chrome plugins folder; make sure you are in this folder before creating the link
-
Print / copy / paste.
sudo ln -s /usr/local/java/jre1.7.0_40/lib/amd64/libnpjp2.so
- This will create a link between Java JRE (Java Runtime Environment) plugin libnpjp2.so and Google Chrome browser
-
Reminders:
-
Attention.
Occasionally, when entering the above commands, the following message may appear:
- ln: creating symbolic link `./libnpjp2.so ': File exists
- To fix this error, remove the previous link with the following command:
-
Print / copy / paste.
cd / opt / google / chrome / plugins
-
Print / copy / paste.
sudo rm -rf libnpjp2.so
- Make sure you are in the / opt / google / chrome / plugins folder before entering this command.
- Restart your browser and open Java Tester to test if Java is working correctly in your browser.
Mozilla Firefox
Instructions for a 32-bit system:
- Enter the following commands.
-
Print / copy / paste.
cd / usr / lib / mozilla / plugins
This will take you to the / usr / lib / mozilla / plugins folder; if such folder does not exist, create it
-
Print / copy / paste.
sudo mkdir -p / usr / lib / mozilla / plugins
This will create the / usr / lib / mozilla / plugins folder; make sure you are in this folder before creating the link
-
Print / copy / paste.
sudo ln -s /usr/local/java/jre1.7.0_40/lib/i386/libnpjp2.so
- This will create a link between Java JRE (Java Runtime Environment) plugin libnpjp2.so and Mozilla Firefox browser
-
Instructions for a 64-bit system:
- Enter the following commands.
-
Print / copy / paste.
cd / usr / lib / mozilla / plugins
This will take you to the / usr / lib / mozilla / plugins folder; if such folder does not exist, create it
-
Print / copy / paste.
sudo mkdir -p / usr / lib / mozilla / plugins
This will create the / usr / lib / mozilla / plugins folder; make sure you are in this folder before creating the link
-
Print / copy / paste.
sudo ln -s /usr/local/java/jre1.7.0_40/lib/amd64/libnpjp2.so
- This will create a link between Java JRE (Java Runtime Environment) plugin libnpjp2.so and Mozilla Firefox browser
-
Reminders:
-
Attention.
Sometimes, when entering the above commands, the following message may appear:
- ln: creating symbolic link `./libnpjp2.so ': File exists
- To fix this error, remove the previous link with the following command:
-
Print / copy / paste.
cd / usr / lib / mozilla / plugins
-
Print / copy / paste.
sudo rm -rf libnpjp2.so
- Make sure you are in the / usr / lib / mozilla / plugins folder before entering this command.
- Restart your browser and open Java Tester to test if Java is working correctly in your browser.
- Enter the following commands.