Blog Archives

Install Oracle JDK in Ubuntu 24.04

Step : 1 Download Oracle JDK 8

Under the “Linux” section, download the Linux x64 Compressed Archive (.tar.gz) file

Step 2: Extract and Move the JDK

Create a directory to install Java in, for example, /usr/lib/jvm/ (if it doesn’t exist):

sudo mkdir -p /usr/lib/jvm

Navigate to your Downloads folder and move the downloaded .tar.gz file to the new directory. (Replace jdk-8uXXX-linux-x64.tar.gz with your actual filename):

sudo mv ~/Downloads/jdk-8uXXX-linux-x64.tar.gz /usr/lib/jvm/

Navigate to the install directory and extract the archive:

cd /usr/lib/jvm/
sudo tar -zxvf jdk-8uXXX-linux-x64.tar.gz

Step 3: Configure Java Alternatives

Use the update-alternatives command to register the newly installed Java executables with the system

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_XXX/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_XXX/bin/javac" 1

Step 4: Set the Default Java Version

If you have multiple Java versions installed, use this command to select Oracle JDK 8 as the default system-wide Java

sudo update-alternatives --config java

Step 5: Set the JAVA_HOME Environment Variable

Open the /etc/environment file using a text editor (like nano or vim) with sudo privileges:

sudo emacs /etc/environment

Add the following line at the end of the file, replacing the path as needed (ensure it points to your JDK directory, not the bin folder to JAVA_HOME), For bin folder amend in PATH variable as shown below.

JAVA_HOME="/usr/lib/jvm/jdk1.8.0_XXX"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/jdk1.8.0_471/bin"

Reload the environment variables:

source /etc/environment

Step 6: Verify the Installation

java -version
echo $JAVA_HOME
Design a site like this with WordPress.com
Get started