This article is for the 32-bit and 64-bit versions of the Oracle Java 8 JDK installation (the version at which this article was written is 1.8.0_20) on 32-bit and 64-bit Ubuntu operating systems. These instructions can also be applied to Debian and Linux Mint.
This tutorial is for those of you who just want to install the Oracle Java JDK with the Oracle Java JRE included in the JDK download. The Oracle Java JDK installation instructions only apply to Debian-based Linux operating systems, for example: Debian, Linux Mint, or Ubuntu.
Step
Step 1. See if your Ubuntu Linux operating system architecture operating is 32 bit or 64 bit
Open terminal and run this command
-
Type/Copy/Paste:
files /sbin/init
Note the bit version of the Ubuntu Linux operating system architecture that appears, whether 32 bit or 64 bit
Step 2. Find out if your system has Java installed
For that, run the java version command from the terminal.
-
Open a terminal, then enter the command below:
-
Type/Copy/Paste:
java -version
-
-
If you already have OpenJDK on your system, this line might appear:
-
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 already exists on your system, the wrong vendor version of Java has been installed on your system.
Step 3. Completely remove OpenJDK/JRE from the system, then create a folder to hold the Oracle Java JDK/JRE binary
This is useful for preventing system conflicts and confusion between different vendor versions of Java. For example, if an OpenJDK/JRE already exists on the system, delete it by typing this command at the command line:
-
Type/Copy/Paste:
sudo apt-get purge openjdk-\*
The above command is to completely remove OpenJDK/JRE from the system
-
Type/Copy/Paste:
sudo mkdir -p /usr/local/java
This command will create a folder to hold the Oracle Java JDK and JRE binaries
Step 4. Download Oracle Java JDK for Linux
You should choose a compressed binary that appropriate for 32 bit or 64 bit system architecture (with tar.gz file extension)
- If you are using the 32 bit Ubuntu Linux operating system, download the 32 bit Oracle Java binary.
- If you are using the 64 bit Ubuntu Linux operating system, download the 64 bit Oracle Java binary.
-
You can also download Oracle Java JDK documentation
Select jdk-8u20-apidocs.zip
-
Vital Records:
Oracle Java 64 bit binary cannot be used on 32 bit Ubuntu Linux operating system. A number of system error messages will appear if you try to install Oracle Java 64 bit on Ubuntu Linux 32 bit.
Step 5. Copy the Oracle Java binary into the local folder /usr/local/java
In most cases the Oracle Java binary is downloaded to: /home/"your_user_name"/Downloads.
-
Oracle Java 32 bit installation instructions on Ubuntu Linux 32 bit:
-
Type/Copy/Paste:
cd /home /' "your_user_name" /Downloads
-
Type/Copy/Paste:
sudo cp -r jdk-8u20-linux-i586.tar.gz /usr/local/java/
-
Type/Copy/Paste:
cd /usr/local/java/
-
-
Oracle Java 64 bit installation instructions on Ubuntu Linux 64 bit:
-
Type/Copy/Paste:
cd /home /' "your_user_name" /Downloads
-
Type/Copy/Paste:
sudo cp -r jdk-8u20-linux-x64.tar.gz /usr/local/java/
-
Type/Copy/Paste:
cd /usr/local/java/
-
Step 6. Extract the compressed Java binary in the /usr/local/java/ folder
-
Oracle Java 32 bit installation instructions on Ubuntu Linux 32 bit:
-
Type/Copy/Paste:
sudo tar xvzf jdk-8u20-linux-i586.tar.gz
-
-
Oracle Java 64 bit installation instructions on Ubuntu Linux 64 bit:
-
Type/Copy/Paste:
sudo tar xvzf jdk-8u20-linux-x64.tar.gz
-
Step 7. Check your folder again
At this point, you should have two extracted binary folders in /usr/local/java/ for the Java JDK/JRE listed as:
-
Type/Copy/Paste:
ls -a
- jdk1.8.0_20
- jre1.8.0_20
Step 8. Edit the PATH file system /etc/profile, then add this system variable to the system path
Use a text editor like nano or gedit as root, then open /etc/profile.
-
Type/Copy/Paste:
sudo gedit /etc/profile
- or
-
Type/Copy/Paste:
sudo nano /etc/profile
Step 9. Scroll to the end of the file using the arrow keys on your keyboard and add the following line at the end of the /etc/profile file:
-
Type/Copy/Paste:
JAVA_HOME=/usr/local/java/jdk1.8.0_20
JRE_HOME=/usr/local/java/jre1.8.0_20
PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
Step 10. Save the /etc/profile file, then exit
Step 11. Tell the Ubuntu Linux system where the Oracle Java JDK/JRE is located
This will notify the system that the new Oracle Java version is available.
-
Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_20/bin/java" 1
This command will notify the system that the Oracle Java JRE is up and running
-
Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_20/bin/javac" 1
This command will notify the system that the Oracle Java JDK is ready to use
-
Type/Copy/Paste:
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_20/bin/javaws" 1
This command notifies the system that Oracle Java Web start is up and running
Step 12. Tell the Ubuntu Linux system that the Oracle Java JDK/JRE must be the default Java
-
Type/Copy/Paste:
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_20/bin/java
This command is to set the Java runtime environment on the system
-
Type/Copy/Paste:
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_20/bin/javac
This command is to set the javac compiler on the system
-
Type/Copy/Paste:
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_20/bin/javaws
This command is to set Java Web start on the system
Step 13. Rerun PATH /etc/profile on the system by typing this command:
-
Type/Copy/Paste:
source /etc/profile
- Note that the PATH /etc/profile on the system will be restarted after the Ubuntu Linux system is restarted
Step 14. Test to see if Oracle Java is properly installed on the system
Run this command and see which version of Java appears:
Step 15. A successful installation of Oracle Java 32 bit will display:
-
Type/Copy/Paste:
java -version
This command will display the Java version currently running on the system
-
A message will appear showing:
-
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) Server VM (build 25.20-b23, mixed mode)
-
-
Type/Copy/Paste:
javac -version
This command is to let you know that you can now compile Java programs from the terminal
-
A message will appear showing:
Javac 1.8.0_20
Step 16. A successful installation of Oracle Java 64 bit will display:
-
Type/Copy/Paste:
java -version
This command will display the Java version currently running on the system
-
A message will appear showing:
-
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) Server VM (build 25.20-b23, mixed mode)
-
-
Type/Copy/Paste:
javac -version
This command is to let you know that you can now compile Java programs from the terminal
-
A message will appear showing:
Javac 1.8.0_20
Step 17. Congratulations
You have successfully installed Oracle Java on your Linux system. Restart the system. After that, the system will be fully configured to run and develop Java programs. Later you can try compiling and running Java programs yourself.
Optional: How to enable Oracle Java in Web Browser
To enable the Java plug-in in a web browser, create a symbolic link from the web browser plug-ins folder to the Java plug-in location in your Oracle Java distribution
Important Information:
Enabling Oracle Java 7 in a web browser will expose many security vulnerabilities and Java exploits. Basically, enabling Oracle Java 7 in a web browser risks inviting hackers into your system. For more information about security vulnerabilities and exploits in Java, visit the following English website: Java Tester
Google Chrome
Oracle Java 32 bit instructions:
-
Enter the command below.
-
Type/Copy/Paste:
sudo mkdir -p /opt/google/chrome/plugins
This command will create a folder named /opt/google/chrome/plugins
-
Type/Copy/Paste:
cd /opt/google/chrome/plugins
This command will put you in the Google Chrome plug-ins folder. You must be in this folder before creating a symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/i386/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) plug-in libnpjp2.so to the Google Chrome web browser.
-
Oracle Java 64 bit instructions:
-
Enter the command below.
-
Type/Copy/Paste:
sudo mkdir -p /opt/google/chrome/plugins
This command will create a folder named /opt/google/chrome/plugins
-
Type/Copy/Paste:
cd /opt/google/chrome/plugins
This command will put you in the Google Chrome plug-ins folder. You must be in this folder before creating the symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/amd64/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) plug-in libnpjp2.so to the Google Chrome web browser.
-
Reminder:
-
Notes:
Sometimes the above command can bring up the following message:
- ln: creating symbolic link `./libnpjp2.so': File exists
- To solve this problem, remove the previous symbolic link using this 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 folder before you enter that command.
-
Restart the web browser and then visit the Java Tester to detect if Java is working in your browser.
Mozilla Firefox
Oracle Java 32 bit instructions:
-
Enter the command below.
-
Type/Copy/Paste:
cd /usr/lib/mozilla/plugins
This command will put you in the /usr/lib/mozilla/plugins folder. Create this folder if it's not already on your system
-
Type/Copy/Paste:
sudo mkdir -p /usr/lib/mozilla/plugins
This command will create a folder called /usr/lib/mozilla/plugins. You must be in this folder before creating the symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/i386/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) plug-in libnpjp2.so to the Mozilla Firefox browser
-
Oracle Java 64 bit instructions:
-
Enter the command below.
-
Type/Copy/Paste:
cd /usr/lib/mozilla/plugins
This command will put you in the /usr/lib/mozilla/plugins folder. Create this folder if it's not already on your system
-
Type/Copy/Paste:
sudo mkdir -p /usr/lib/mozilla/plugins
This command will create a folder called /usr/lib/mozilla/plugins. You must be in this folder before creating the symbolic link
-
Type/Copy/Paste:
sudo ln -s /usr/local/java/jdk1.8.0_20/jre/lib/amd64/libnpjp2.so
This command will create a symbolic link from the Java JRE (Java Runtime Environment) plug-in libnpjp2.so to the Mozilla Firefox browser
-
Reminder:
-
Notes:
Sometimes the above command can bring up the following message:
- ln: creating symbolic link `./libnpjp2.so': File exists
- To solve this problem, remove the previous symbolic link using this 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 folder before you enter that command.
-
Restart the web browser and then visit the Java Tester to detect if Java is working in your browser.
-