---Advertisement---

How to Install Java on Ubuntu (Linux):-

By Shiva

Published 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.

  • 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.

๐Ÿ‘‰Installing Java on Ubuntu (Linux):-

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.

๐Ÿ‘‰Step 1: Update Package Repository:-

Before installing Java, update your package list:

bash

sudo apt update && sudo apt upgrade -y.

๐Ÿ‘‰Step 2: Install OpenJDK:-

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

๐Ÿ‘‰Step 3: Verify Java Installation:-

Check the installed Java version:

bash

java -version.

Expected output (for Java 17):

๐Ÿ‘‰Method 2: Installing Oracle Java (Manual Installation):-

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

๐Ÿ‘‰Step 1: Remove Existing OpenJDK Versions:

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

bash

sudo apt purge openjdk-\* -y

๐Ÿ‘‰Step 2: Download Oracle JDK:

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

๐Ÿ‘‰Step 3: Extract and Install JDK:

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

๐Ÿ‘‰Step 4: Set Java Environment Variables:

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

๐Ÿ‘‰Step 5: Set Oracle JDK as Default:

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.

๐Ÿ‘‰Step 6: Verify Java Installation:

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)
.

๐Ÿ‘‰Choosing the Right Java Version:

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.

๐Ÿ‘‰Conclusion:-

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. ๐Ÿš€.

---Advertisement---

Leave a Comment