How to Install Oracle Java on Ubuntu Linux – Step‑by‑Step Guide
Follow this concise, expert‑verified guide to install the latest Oracle JDK on Ubuntu. Whether you’re running a 32‑bit or 64‑bit system, these steps will have Java up and running in minutes.
1. Remove Existing OpenJDK Packages
Ubuntu often ships with OpenJDK pre‑installed. To avoid conflicts, purge all OpenJDK packages first:
sudo apt-get purge openjdk-*
Confirm the removal when prompted.
2. Verify Your System Architecture
Determine if your Ubuntu installation is 32‑bit or 64‑bit:
file /sbin/init
Look for “x86_64” (64‑bit) or “i386” (32‑bit) in the output.
3. Download the Correct Oracle JDK Package
Visit the official Oracle Java SE download page: Oracle Java Downloads. Accept the license agreement and choose:
- For 32‑bit: x86 + tar.gz (Ubuntu)
- For 64‑bit: x64 + tar.gz (Ubuntu)
- Alternatively, download the rpm package for Debian‑based systems.
After downloading, you’ll see a file like jdk-8u5-linux-x64.tar.gz in your Downloads folder.
4. Extract the JDK Archive
Navigate to the download location and extract the archive:
cd ~/Downloads sudo tar -xvf jdk-8u5-linux-x64.tar.gz
After extraction, a folder such as jdk1.8.0_5 will appear.
5. Set System Environment Variables
Open /etc/profile for editing:
sudo nano /etc/profile
Add the following lines at the end, replacing /path/to/jdk with the actual extraction path:
JAVA_HOME=/path/to/jdk PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME export PATH
Save the file (Ctrl+X, then Y, Enter).
6. Reload Profile Settings
. /etc/profile
7. Register the JDK with Ubuntu’s Alternatives System
Tell the system where Java binaries are located:
sudo update-alternatives --install "/usr/bin/java" "java" "/path/to/jdk/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/path/to/jdk/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/path/to/jdk/bin/javaws" 1
8. Make the Oracle JDK the Default
sudo update-alternatives --set java "/path/to/jdk/bin/java" sudo update-alternatives --set javac "/path/to/jdk/bin/javac" sudo update-alternatives --set javaws "/path/to/jdk/bin/javaws"
9. Verify the Installation
Check that Java reports the correct version:
java -version
You should see output similar to:
java version "1.8.0_5" Java(TM) SE Runtime Environment (build 1.8.0_5-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b13, mixed mode)
Congratulations – Oracle Java is now installed and ready to use on your Ubuntu system.
Java
- Installing Dev‑C++ on Windows: Step‑by‑Step Guide
- Installing Visual Studio 2019 Community Edition for C# Development on Windows
- How to Install GCC Compiler on Windows, macOS, and Linux: A Step‑by‑Step Guide
- How to Download and Install Java JDK 8 on Windows 10 (64‑Bit) – Step‑by‑Step Guide
- Step‑by‑Step Guide: Downloading and Installing Eclipse IDE for Java
- Creating an Array of Objects in Java: A Step‑by‑Step Guide
- Generate Random Numbers in Java: Practical Guide with Random and Math.random
- Java 9 Module System: Enhancements, Link‑Time, and Custom Runtime Images
- Step‑by‑Step Guide: Installing PoE IP CCTV Cameras with an NVR System
- Expert Guide to Designing & Installing Solar PV Systems