This article provides a comprehensive guide for installing Oracle Java 7, both 32-bit and 64-bit versions (current version 1.7.0_45), including JDK and JRE, on Ubuntu operating systems in 32-bit and 64-bit architectures. The instructions are also applicable to Debian and Linux Mint.
If you already have Oracle Java 7 installed on your system but wish to upgrade, refer to the guide on upgrading Oracle Java on Ubuntu Linux.
For users who only need to install Oracle Java JRE to run Java applications without developing Java programs, check out the guide on installing Oracle Java JRE on Ubuntu Linux.
For those looking to install Oracle Java JDK for developing Java programs and applications (Oracle Java JRE is included in Oracle JDK), follow the method below:
- How to Install Oracle Java JDK on Ubuntu Linux
To enable or upgrade Oracle Java on your web browser, refer to the guide on enabling Oracle Java on web browsers.
Steps

-
Type//Paste: file /sbin/init
- Take note of whether your Ubuntu Linux operating system is 32-bit or 64-bit.

- Open the terminal and enter the following command:
- Type//Paste: java -version
- If OpenJDK is installed on your system, you will see a message like:
- 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)
- java version "1.7.0_15"
- If OpenJDK is installed on your system, this is not the vendor version mentioned in this article.

-
Type//Paste: sudo apt-get purge openjdk-\*
- This command completely removes OpenJDK/JRE from the system.
-
Type//Paste: sudo mkdir -p /usr/local/java
- This command creates a new directory to store Oracle Java JDK and JRE binaries.

- For example, if using Ubuntu Linux 32-bit, download the Oracle Java 32-bit binaries.
- For example, if using Ubuntu Linux 64-bit, download the Oracle Java 64-bit binaries.
- Optionally, Download Oracle Java JDK/JRE Documentation
- Select jdk-7u40-apidocs.zip
- Important Note: Oracle Java 64-bit binaries will not work on a 32-bit Ubuntu Linux system, and attempting to install them will result in multiple system error messages.

-
Instructions for installing Oracle Java 32-bit on Ubuntu Linux 32-bit:
- Type//Paste: cd ~/Downloads
- Type//Paste: sudo cp -r jdk-7u45-linux-i586.tar.gz /usr/local/java
- Type//Paste: sudo cp -r jre-7u45-linux-i586.tar.gz /usr/local/java
- Type//Paste: cd /usr/local/java
-
Instructions for installing Oracle Java 64-bit on Ubuntu Linux 64-bit:
- Type//Paste: cd ~/Downloads
- If you downloaded JDK, Type//Paste: sudo cp -r jdk-7u45-linux-x64.tar.gz /usr/local/java
- If you downloaded JRE, Type//Paste: sudo cp -r jre-7u45-linux-x64.tar.gz /usr/local/java
- Type//Paste: cd /usr/local/java

-
Instructions for installing Oracle Java 32-bit on Ubuntu Linux 32-bit:
- Type//Paste: sudo tar xvzf jdk-7u45-linux-i586.tar.gz
- Type//Paste: sudo tar xvzf jre-7u45-linux-i586.tar.gz
-
Instructions for installing Oracle Java 64-bit on Ubuntu Linux 64-bit:
- If you downloaded JDK, Type//Paste: sudo tar xvzf jdk-7u45-linux-x64.tar.gz
- If you downloaded JRE, Type//Paste: sudo tar xvzf jre-7u45-linux-x64.tar.gz

- Type//Paste: ls -a
- jdk1.7.0_45
- or jre1.7.0_45

- Type//Paste: sudo gedit /etc/profile
- or
- Type//Paste: sudo nano /etc/profile

-
If you installed JDK, Type//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 -
If you installed JRE, Type//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.

- If you installed JDK, Type//Paste: sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_45/jre/bin/java" 1
-
If you installed JRE, Type//Paste: sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_45/bin/java" 1
- This command informs the system that Oracle Java JRE is ready for use.
-
Only if you installed JDK, Type//Paste:sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_45/bin/java" 1
- This command informs the system that Oracle Java JDK is ready for use.
-
Type//Paste:sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_45/bin/javaws" 1
- This command informs the system that Oracle Java Web is ready for use.

- If you installed JDK, Type//Paste: sudo update-alternatives --set java /usr/local/java/jdk1.7.0_45/jre/bin/java
-
If you installed JRE, Type//Paste:sudo update-alternatives --set java /usr/local/java/jre1.7.0_45/bin/java
- This command sets the Java runtime environment for the system.
-
Only if you installed JDK, Type//Paste: sudo update-alternatives --set java /usr/local/java/jdk1.7.0_45/bin/java
- This command sets the Java compiler for the system.
- If you installed JDK, Type//Paste: sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_45/bin/javaws
-
If you installed JRE, Type//Paste: sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_45/bin/javaws
- This command sets Java Web Start for the system.

- Type//Paste: . /etc/profile
- The system path /etc/profile file will reload after restarting the Ubuntu Linux system.

-
Type//Paste: java -version. This command displays the Java version on your system. You will see the message: 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//Paste: java -version. This command confirms that you can now compile Java programs from the terminal. You will receive the following message: java 1.7.0_45. A successful installation of Oracle Java 64-bit will display:
-
Type//Paste: java -version. This command shows the Java version running on your system. You will receive the following message: 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//Paste: java -version. This command confirms that you can now compile Java programs from the terminal. You will see the message: java 1.7.0_45

Optional: How to Enable Oracle Java on Web Browsers

- Important Note: Exercise caution when enabling Oracle Java 7 on your web browser, as Java is known to have numerous security vulnerabilities and exploits. More importantly, enabling Oracle Java 7 on your web browser can expose your system to potential attacks if security flaws are exploited. For more information on Java vulnerabilities and exploits, visit: Java Tester
Google Chrome
Oracle Java 32-bit Guide:

-
Type//Paste: sudo mkdir -p /opt/google/chrome/plugins
- This command creates the /opt/google/chrome/plugins directory.
-
Type//Paste: cd /opt/google/chrome/plugins
- This command navigates you to the Google Chrome plugins directory. Ensure you are in this directory before creating the symbolic link.
-
Type//Paste: sudo ln -s /usr/local/java/jre1.7.0_45/lib/i386/libnpjp2.so
- This command creates a symbolic link from the Java JRE (Java Runtime Environment) plugin libnpjp2.so to the Google Chrome browser.
Oracle Java 64-bit Guide:

-
Type//Paste: sudo mkdir -p /opt/google/chrome/plugins
- This command creates the /opt/google/chrome/plugins directory.
-
Type//Paste: cd /opt/google/chrome/plugins
- This command takes you to the Google Chrome plugins directory. Make sure you are in this directory before creating the symbolic link.
-
Type//Paste: sudo ln -s /usr/local/java/jre1.7.0_45/lib/amd64/libnpjp2.so
- This command creates a symbolic link from the Java JRE (Java Runtime Environment) plugin libnpjp2.so to the Google Chrome browser.
Reminder:

- ln: creating symbolic link `./libnpjp2.so': File exists
- To resolve this issue, simply remove the previous link using the following command:
- Type//Paste: cd /opt/google/chrome/plugins
- Type//Paste: sudo rm -rf libnpjp2.so
- Ensure you are in the /opt/google/chrome/plugins directory before executing the command.

Mozilla Firefox
Oracle Java 32-bit Guide:

-
Type//Paste: cd /usr/lib/mozilla/plugins
- This command takes you to the /usr/lib/mozilla/plugins directory. Create this directory if it does not exist.
-
Type//Paste: sudo mkdir -p /usr/lib/mozilla/plugins
- This command creates the /usr/lib/mozilla/plugins directory. Ensure you are in this directory before creating the symbolic link.
-
Type//Paste: sudo ln -s /usr/local/java/jre1.7.0_45/lib/i386/libnpjp2.so
- This command creates a symbolic link from the Java JRE (Java Runtime Environment) plugin libnpjp2.so to the Mozilla Firefox web browser.
Oracle Java 64-bit Guide:

-
Type//Paste: cd /usr/lib/mozilla/plugins
- This command takes you to the /usr/lib/mozilla/plugins directory. Create this directory if it does not exist.
-
Type//Paste: sudo mkdir -p /usr/lib/mozilla/plugins
- This command creates the /usr/lib/mozilla/plugins directory. Ensure you are in this directory before creating the symbolic link.
-
Type//Paste: sudo ln -s /usr/local/java/jre1.7.0_45/lib/amd64/libnpjp2.so
- This command creates a symbolic link from the Java JRE (Java Runtime Environment) plugin libnpjp2.so to the Mozilla Firefox web browser.
Reminder:

- ln: creating symbolic link `./libnpjp2.so': File exists
- To resolve this issue, simply remove the previous link using the following command:
- Type//Paste: cd /usr/lib/mozilla/plugins
- Type//Paste: sudo rm -rf libnpjp2.so
- Ensure you are in the /usr/lib/mozilla/plugins directory before executing the command.
Advice
- For Ubuntu Linux, you can choose between OpenJDK, a free and open-source implementation of the Java programming language, or Oracle Java JDK and JRE. Some users prefer Oracle Java (as it is the latest updated version of Java and comes from the maintainers of Java technology), but preferences may vary.
- Keep in mind that Oracle releases security updates, bug fixes, and performance improvements with each Java update. When installing Oracle Java on your system, pay attention to the version number. Refer to additional guides on upgrading Oracle Java on Linux for more details.
- Note that this article is frequently updated, as Oracle occasionally changes the installation methods for Java JDK/JRE binaries.
