
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.
๐Why Install Java on Ubuntu?
- 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:
bashsudo apt update && sudo apt upgrade -y
.
๐Step 2: Install OpenJDK:-
To install OpenJDK 17 (latest stable version):
bashsudo apt install openjdk-17-jdk -y
.
For Java 11:
bashsudo apt install openjdk-11-jdk -y
For Java 8:
bashsudo apt install openjdk-8-jdk -y
๐Step 3: Verify Java Installation:-
Check the installed Java version:
bash
java -version.
Expected output (for Java 17):
pgsqlopenjdk version "17.0.8" 2024-03-10
.
OpenJDK Runtime Environment (build 17.0.8+10-Ubuntu)
OpenJDK 64-Bit Server VM (build 17.0.8+10-Ubuntu)
๐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:
bashsudo 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:
bashsudo tar -xvf jdk-17_linux-x64_bin.tar.gz -C /usr/lib/jvm/
Rename the extracted folder (for easier management):
bashsudo mv /usr/lib/jvm/jdk-17* /usr/lib/jvm/java-17-oracle
๐Step 4: Set Java Environment Variables:
Edit the profile file:
bashsudo nano /etc/profile
Add the following lines at the bottom:
bashexport 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:
bashsource /etc/profile
๐Step 5: Set Oracle JDK as Default:
bashsudo 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:
bashjava -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 Version | Best For |
Java 8 | Legacy 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. ๐.