---Advertisement---

How to Install Java on Ubuntu (Linux) Great 2025

By Shiva

Updated On:

---Advertisement---

Java is an essential programming language for developers, and installing it on Ubuntu is a straightforward process. This guide will walk you through installing Java (JDK) on Ubuntu, ensuring a proper setup for development and execution.

To install Java on Ubuntu, update the package index using sudo apt update, then install Java with sudo apt install default-jdk. Verify the installation using java -version. This method installs the default OpenJDK, suitable for most applications. For specific versions like Oracle JDK, add the official repository. Java is essential for running Java-based apps and development on Ubuntu systems.

  • Required for running Java-based applications.
  • Essential for software development using tools like Eclipse, IntelliJ, and Android Studio.
  • Needed for running Java-based web services and enterprise applications.

There are two main ways to install Java on Ubuntu:

Method 1: Installing OpenJDK (Recommended for Most Users):

Ubuntu provides OpenJDK in its official repositories, making installation simple.

Before installing Java, update your package list:

bash

sudo apt update && sudo apt upgrade -y.

To install OpenJDK 17 (latest stable version):

bash

sudo apt install openjdk-17-jdk -y.

For Java 11:

bash

sudo apt install openjdk-11-jdk -y

For Java 8:

bash

sudo apt install openjdk-8-jdk -y

Check the installed Java version:

bash

java -version.

Expected output (for Java 17):

Oracle JDK offers long-term support (LTS) versions with additional performance optimizations.

If OpenJDK is installed, remove it before installing Oracle Java:

bash

sudo apt purge openjdk-\* -y

Visit the https://www.oracle.com/java/technologies/downloads/ and download the latest JDK .tar.gz file.

Navigate to the directory where the file is downloaded and extract it:

bash

sudo tar -xvf jdk-17_linux-x64_bin.tar.gz -C /usr/lib/jvm/

Rename the extracted folder (for easier management):

bash

sudo mv /usr/lib/jvm/jdk-17* /usr/lib/jvm/java-17-oracle

Edit the profile file:

bash

sudo nano /etc/profile

Add the following lines at the bottom:

bash

export JAVA_HOME=/usr/lib/jvm/java-17-oracle
export PATH=$PATH:$JAVA_HOME/bin

Save and exit (CTRL+X, then Y and Enter).

Apply changes:

bash

source /etc/profile
bash

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-17-oracle/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-17-oracle/bin/javac" 1
sudo update-alternatives --config java

Select the Oracle JDK version if prompted.

bash

java -version

Expected output (for Oracle JDK 17):

scssjava version "17.0.8" 2024-03-10 LTS
Java(TM) SE Runtime Environment (build 17.0.8+10)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.8+10, mixed mode)
.
Java VersionBest For
Java 8Legacy applications, older projects.
Java 11 (LTS)General-purpose use, enterprise applications.
Java 17 (LTS)Latest LTS, recommended for new projects.
Java 21 (Upcoming LTS)Cutting-edge features, future-proofing.

Installing Java on Ubuntu is easy using either OpenJDK (for general use) or Oracle JDK (for performance and commercial support). OpenJDK is preferred for most users due to its open-source nature, while Oracle JDK is ideal for enterprise applications.

Keywords:-

  • Install Java on Ubuntu.
  • Java JDK installation guide.
  • Install OpenJDK on Linux.
  • Ubuntu Java setup.
  • Oracle JDK installation Linux.
  • Best Java version for Ubuntu.

By following this guide, youโ€™ll have a working Java environment ready for development and execution on Ubuntu. ๐Ÿš€.

Leave a Comment

Index