Installing Oracle JDK on Ubuntu – Step-by-Step Guide

Linux Tips

Introduction

Hey there!
Today I’ll walk you through how to install Oracle JDK on Ubuntu.

I normally use NetBeans, which comes bundled with the JDK, but when switching to Eclipse, you’ll need to install the JDK manually. So I documented the process as a personal cheat sheet — and I’m sharing it here in case it helps someone else!

This guide is for Oracle Java 8 (JDK 1.8.0_20) and has been tested on Ubuntu 15.10, but it should also work on Debian-based systems like Linux Mint and Debian itself.


Step-by-Step Installation

1. Check Your System Architecture

file /sbin/init

This will tell you if you are running a 32-bit or 64-bit system.


2. Check if Java is Already Installed

java -version

If you see something like:

java version "1.7.0_15"
OpenJDK Runtime Environment

Then you have OpenJDK, and for this tutorial, we’ll be removing it.


3. Remove OpenJDK and Create a Java Directory

sudo apt-get purge openjdk-*
sudo mkdir -p /usr/local/java

4. Download Oracle JDK

Go to the official Oracle website and download the appropriate version:

  • jdk-8u20-linux-i586.tar.gz for 32-bit
  • jdk-8u20-linux-x64.tar.gz for 64-bit

5. Copy the Archive to /usr/local/java

cd ~/Downloads
sudo cp -r jdk-8u20-linux-x64.tar.gz /usr/local/java/
cd /usr/local/java

(Adjust filename depending on your architecture.)


6. Extract the Archive

sudo tar xvzf jdk-8u20-linux-x64.tar.gz

You should now see directories like:

jdk1.8.0_20
jre1.8.0_20

7. Add Environment Variables

Edit /etc/profile:

sudo nano /etc/profile

Add the following at the end of the file:

JAVA_HOME=/usr/local/java/jdk1.8.0_20
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH

Save and exit (CTRL+X, confirm with Y, and hit ENTER).


8. Register Oracle Java with the System

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_20/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_20/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_20/bin/javaws" 1

9. Set Oracle Java as Default

sudo update-alternatives --set java /usr/local/java/jdk1.8.0_20/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_20/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_20/bin/javaws

10. Reload the System Path

source /etc/profile

This will also load automatically after the next reboot.


11. Verify the Installation

java -version

You should see something like:

java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
javac -version

Output:

javac 1.8.0_20

Conclusion

✅ That’s it! You’ve successfully installed Oracle Java JDK on your Ubuntu system. Now you’re ready to build and run Java apps using your favorite IDE — whether it’s Eclipse, IntelliJ, or NetBeans.

Restart your machine, and happy coding!


See you next time! 👋


¿Querés que ahora hagamos una versión más moderna para JDK 21 o una instalación vía SDKMAN? También puedo adaptar esta guía como parte de una serie de "Java en Linux".

Comments

Search

Cargando buscador...