This tutorial will cover installing both 32-bit and 64-bit Oracle Java 7 JDK/JRE (current version number is 1.7.0_45) on 32-bit and 64-bit Ubuntu operating systems. This guide also applies to Debian and Linux Mint. For those of you who only want to install the Oracle Java JRE to run Java applications and not to develop Java programs, use this way:
Installing Oracle Java JRE on Linux Ubuntu
For those of you who want to install the Oracle Java JDK to develop Java programs and applications (the Oracle Java JRE is also included in the Oracle JDK), use this method:
Installing Oracle Java JDK on Ubuntu Linux
Step
Step 1. Check if your Ubuntu Linux operating system is 32-bit or 64-bit architecture
Open a terminal and run the command below.
-
Type/Copy/Paste:
files /sbin/init
The bit version of your Ubuntu Linux operating system architecture will display as 32-bit or 64-bit
Step 2. Check if Java is already installed on your system
To do this, you need to run the Java version of the command from the terminal.
-
Open a terminal and enter the following command:
-
Type/Copy/Paste:
java -version
-
-
If OpenJDK is already installed on the system, the following text will appear on the screen:
-
java version "1.7.0_15"
OpenJDK Runtime Environment (IcedTea6 1.10pre) (7b15~pre1-0lucid1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
-
- If OpenJDK is already installed on your system, it means that you have the wrong vendor version of Java for this method.
Step 3. Remove OpenJDK/JRE from your system and create a directory to hold your Oracle Java JDK/JRE binary
This will prevent the system from experiencing conflicts and confusion due to different versions of Java vendors. For example, if you have OpenJDk/Jre installed on your system, you can remove it by typing the following command line:
-
Type/Copy/Paste:
sudo apt-get purge openjdk-\*
This command will completely detach OpenJDK/JRE from your system
-
Type/Copy/Paste:
sudo mkdir -p /usr/local/java
This command will create a directory to hold your Oracle Java JDK and JRE binaries
Step 4. Download Oracle Java JDK/JRE for Linux
Make sure you choose compressed binary right for 32-bit or 64-bit system architectures (those ending in tar.gz).
- For example, if you are using the 32-bit Ubuntu Linux operating system, download the 32-bit Oracle Java binary.
- For example, if you are using the 64-bit Ubuntu Linux operating system, download the 64-bit Oracle Java binary.
-
Optional, Download Oracle Java JDK/JRE Documentation
Select jdk-7u40-apidocs.zip
-
Important Information:
64-bit Oracle Java binary does not work on 32-bit Ubuntu Linux operating system. If you try to install 64-bit Oracle Java on 32-bit Ubuntu Linux, you will receive many system error messages.
Step 5. Copy the Oracle Java binary to the /usr/local/java directory
In most cases the Oracle Java binary will be downloaded to: /home/"your_user_name"/Downloads.
-
Guide to installing Oracle Java 32-bit on Linux Ubuntu 32-bit:
-
Type/Copy/Paste:
cd ~/Downloads
-
Type/Copy/Paste:
sudo cp -r jdk-7u45-linux-i586.tar.gz /usr/local/java
-
Type/Copy/Paste:
sudo cp -r jre-7u45-linux-i586.tar.gz /usr/local/java
-
Type/Copy/Paste:
cd /usr/local/java
-
-
Oracle Java 64-bit installation guide on Linux Ubuntu 64-bit:
-
Type/Copy/Paste:
cd ~/Downloads
-
If you have downloaded the JDK, Type/Copy/Paste:
sudo cp -r jdk-7u45-linux-x64.tar.gz /usr/local/java
-
Or, if you've downloaded the JRE, Type/Copy/Paste:
sudo cp -r jre-7u45-linux-x64.tar.gz /usr/local/java
-
Type/Copy/Paste:
cd /usr/local/java
-
Step 6. Open the compressed Java binary into the directory /usr/local/java
-
Guide to installing Oracle Java 32-bit on Linux Ubuntu 32-bit:
-
Type/Copy/Paste:
sudo tar xvzf jdk-7u45-linux-i586.tar.gz
-
Type/Copy/Paste:
sudo tar xvzf jre-7u45-linux-i586.tar.gz
-
-
Oracle Java 64-bit installation guide on Linux Ubuntu 64-bit:
-
If you have downloaded the JDK, Type/Copy/Paste:
sudo tar xvzf jdk-7u45-linux-x64.tar.gz
-
Or if you have downloaded the JRE, Type/Copy/Paste:
sudo tar xvzf jre-7u45-linux-x64.tar.gz
-
Step 7. Check your directories again
At this point, you should have an uncompressed binary directory in /usr/local/java for the Java JDK/JRE that says:
-
Type/Copy/Paste:
ls -a
- jdk1.7.0_45
- or jre1.7.0_45
Step 8. Edit the system PATH file /etc/profile and add the following system variables to your system path
Use nano, gedit, or another text editor, and open /etc/profile as root (root).
-
Type/Copy/Paste:
sudo gedit /etc/profile
- or
-
Type/Copy/Paste:
sudo nano /etc/profile
Step 9. Scroll to the bottom of the file using the arrow keys and add the following line at the end of your /etc/profile file:
-
If you have the JDK installed, Type/Copy/Paste:
JAVA_HOME=/usr/local/java/jdk1.7.0_45
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
-
Or if you have the JRE installed, Type/Copy/Paste:
JRE_HOME=/usr/local/java/jre1.7.0_45
PATH=$PATH:$JRE_HOME/bin
export JRE_HOME
export PATH
- Save the /etc/profile file and exit.
Step 10. Tell the location of the Oracle JDK/JRE to the Ubuntu Linux system
Thus, the system will be notified that the new version of Oracle Java can be used.
-
If you have the JDK installed, Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_45/jre/bin/java" 1
-
Or, If you have the JRE installed, Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_45/bin/java" 1
This command will notify the system that the Oracle Java JRE is up and running
-
Only if you have the JDK installed, Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_45/bin/java" 1
This command tells you that the Oracle Java JDK is ready to use
-
Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_45/bin/javaws" 1
this command notifies the system that Oracle Java Web start can be used
Step 11. Tell Linux Ubuntu that the Oracle Java JDK/JRE should be the default Java
-
If you have the JDK installed, Type/Copy/Paste:
sudo update-alternatives --set java /usr/local/java/jdk1.7.0_45/jre/bin/java
-
Or if you have the JRE installed, Type/Copy/Paste:
sudo update-alternatives --set java /usr/local/java/jre1.7.0_45/bin/java
This command will set up the JRE (Java Runtime Environment) for the system
-
Only if you have the JDK installed, Type/Copy/Paste:
sudo update-alternatives --set java /usr/local/java/jdk1.7.0_45/bin/java
This command will set the Java compiler for the system
- If you have the JDK installed, Type/Copy/Paste sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_45/bin/javaws
-
Or, if you have the JRE installed, Type/Copy/Paste:
sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_45/bin/javaws
This command will set up Web start Java for the system
Step 12. Reload your system wide PATH /etc/profile by typing the following command:
-
Type/Copy/Paste:
. /etc/profile
- Note that your system-wide PATH /etc/profile file will reload after Linux Ubuntu is rebooted.
Step 13. Test if Oracle Java is properly installed on your system
Run the following command and note the Java version:A correct 32-bit Oracle Java installation will display:
-
Type/Copy/Paste:
java -version. This command displays the version of Java the system is running. You should see a message that says: java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
- Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)
-
Type/Copy/Paste:
java -version. This command tells you that you can now compose Java programs from the terminal. You will see a message that says: java 1.7.0_45. A successful installation of Oracle Java 64-bit will display:
-
Type/Copy/Paste:
java -version. This command displays the version of Java the system is running. You will see a message that says: java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
- Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
-
Type/Copy/Paste:
java -version. This command tells you that you can now compose Java programs from the terminal. You should see a message that says: java 1.7.0_45
Step 14. Congratulations, you have installed Oracle Java on your Linux system
Now, reboot your Linux Ubuntu. After that, your system will be fully configured to run and develop Java programs.
Method 1 of 3: Optional: How to Enable Oracle Java in Web Browser
Step 1. Enable Java plug-ins in your web browser by creating a symbolic link from the browser plug-in directory to the Java plug-in location in the Oracle Java distribution
-
Vital Records:
I highly recommend caution when enabling Oracle Java 7 in a web browser because of the many flaws in terms of security and exploits. In essence, if you enable Oracle Java 7 in your web browser, malicious people can enter and damage your computer by exploiting its flaws and weak points. For more information, visit Java Tester
Method 2 of 3: Google Chrome
Guide for Oracle Java 32-bit:
Step 1. Enter the following command
-
Type/Copy/Paste:
sudo mkdir -p /opt/google/chrome/plugins
A directory called /opt/google/chrome/plugins will be created
-
Type/Copy/Paste:
cd /opt/google/chrome/plugins
This command will change you to the Google Chrome add-ons directory, so make sure you are in the directory before the symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jre1.7.0_45/lib/i386/libnpjp2.so
This command will create a symbolic link from the JRE Java (Java Runtime Environment) plugin libnpjp2.so to your Google Chrome.
Guide for Oracle Java 64-bit:
Step 1. Enter the following command
-
Type/Copy/Paste:
sudo mkdir -p /opt/google/chrome/plugins
A directory named /opt/google/chrome/plugins will be created
-
Type/Copy/Paste:
cd /opt/google/chrome/plugins
This command will change you to the Google Chrome add-ons directory, so make sure you are in the directory before creating a symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jre1.7.0_45/lib/amd64/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) add-on libnpjp2.so to Google Chrome.
Reminder:
Step 1. Note:
Sometimes when you enter the above command, a message will appear saying:
- ln: creating symbolic link `./libnpjp2.so': File exists
- To fix 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 you enter the command
Step 2. Restart the web browser and go to the Java Tester to test if Java is working properly in the web browser
Method 3 of 3: Mozilla Firefox
Oracle Java 32-bit Guide:
Step 1. Enter the following command
-
Type/Copy/Paste:
cd /usr/lib/mozilla/plugins
This command will change you to the /usr/lib/mozilla/plugins directory, create this directory if it doesn't already exist
-
Type/Copy/Paste:
sudo mkdir -p /usr/lib/mozilla/plugins
This command will create a directory /usr/lib/mozilla/plugins, so make sure you are in this directory before creating a symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jre1.7.0_45/lib/i386/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) add-on libnpjp2.so to your Mozilla Firefox
Step 2. ====Guide for Oracle Java 64-bit:
====
Step 3. Enter the following command
-
Type/Copy/Paste:
cd /usr/lib/mozilla/plugins
This command will change you to the /usr/lib/mozilla/plugins directory, create this directory if it doesn't already exist
-
Type/Copy/Paste:
sudo mkdir -p /usr/lib/mozilla/plugins
This command will create a directory /usr/lib/mozilla/plugins, so make sure you are in this directory before creating a symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jre1.7.0_45/lib/amd64/libnpjp2.so
This command will create a symbolic link from the Java JRE(Java Runtime Environment) add-on libnpjp2.so to Mozilla Firefox.
Reminder:
Step 1. Note:
Sometimes, when you enter the above command, the following message may appear:
- ln: creating symbolic link `./libnpjp2.so': File exists
- To fix 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 entering the command.
Step 2. Restart your web browser and go to the Java Tester site to test if Java is working properly in the web browser
Tips
- To use Ubuntu Linux, you can choose to use OpenJDK, which is a free and open source implementation of the Java programming language, or use the Oracle Java JDK or JRE. Some people prefer Oracle Java (because it is the most up-to-date version of Java and provided directly by the Java technology maintainer), but choose according to your preference.
- Keep in mind that Oracle updates security, fixes bugs, and raises performance issues every time it releases a new Oracle Java. When installing Oracle Java to the system, make sure you know the version number.
- Be aware that this document is revised periodically as Oracle sometimes changes how the JDK/JRE binary is installed.