Table of Contents
  • Home
  • /
  • Blog
  • /
  • Step by Step Guide to Install Java on Ubuntu Linux
January 1, 2024
|
4m

Step by Step Guide to Install Java on Ubuntu Linux


Install Java On Ubuntu Linux

Java is one of the most popular programming platforms used by developers around the world. Whether you want to run Java applications or develop them yourself, having Java installed on your Ubuntu system is essential.

In this beginner-friendly guide, I’ll walk you through the steps to install different versions of Java on your Ubuntu 22.04 LTS system. We will cover installing both the Java Runtime Environment (JRE) to run Java programs and the full Java Development Kit (JDK) to compile Java code.

Prerequisites

Before installing Java, make sure your Ubuntu system is fully updated by running:

sudo apt update && sudo apt upgrade

This will fetch the latest updates from the Ubuntu repositories and prep your system.

OpenJDK vs Oracle JDK Key Differences

When installing Java on Ubuntu, you have the option of using the free and open-source OpenJDK or the official Oracle Java Development Kit. Here are some key differences:

Licensing:

  • OpenJDK is licensed under GPL and can be freely used in commercial applications

  • Oracle JDK is proprietary and requires a commercial license for business use

Performance:

  • OpenJDK and Oracle JDK generally have similar runtime performance

  • Some benchmarks show Oracle JDK slightly faster in certain workloads

Features:

  • OpenJDK provides all core Java features and keeps up with Oracle’s releases

  • Some advanced management and monitoring tools only available with Oracle JDK

Support:

  • OpenJDK is community-supported with Ubuntu forums/chat available

  • Oracle provides official support, updates and patches for Oracle JDK

So in summary, OpenJDK works great for most developer needs and Ubuntu systems. But certain commercial software products may mandate using Oracle Java. For proprietary applications, the paid Oracle JDK support may also be preferred.

Hope this gives you the context to decide which Java distribution better meets your needs!

Install Default Java OpenJDK JRE/JDK

The easiest way to install Java is via Ubuntu’s default repositories which contain OpenJDK – the open-source version of Java.

To install OpenJDK 11, run:

sudo apt install default-jre default-jdk

This will install both the JRE and JDK. To confirm, check their versions:

java -version
javac -version

Install Oracle Java JDK

If you require the official Oracle Java JDK, you’ll need to manually install it.

First, add Oracle’s PPA to apt:

sudo add-apt-repository ppa:linuxuprising/java

Then update apt and install the latest Java JDK 11:

sudo apt update 
sudo apt install oracle-java11-installer

Once done, you can check the installed version:

java -version

And to set it as the default Java:

sudo update-alternatives --config java

Install Specific Java JDK Version

If you need an older Java version like Java 8 or 17, run:

sudo apt install oracle-java8-installer
sudo apt install oracle-java17-installer

Again check the version with java -version and update alternatives if needed.

Set JAVA_HOME Environment Variable

No matter whetever the Java version you install. You may need to set the env variable. Many Java apps and servers require the JAVA_HOME env variable set to function properly.

To set this permanently on Ubuntu, edit /etc/environment and add:

nano /etc/environment

OpenJDK

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Oracle JDK

JAVA_HOME="/usr/lib/jvm/java-11-oracle"

Just remember to replace the path with where your preferred Java version is installed.

After saving the changes, run source /etc/environment to reload the file. Java should now be fully up and running!

Conclusion

Installing Java runtime and development kits on Ubuntu is super easy whether you want to use OpenJDK or Oracle’s official distribution.

Now you can install IntelliJ, Eclipse, or other Java IDEs to start developing your own applications on Ubuntu!

Let me know in the comments if you have any issues getting Java running on your system.

We hope this post helps learning how to install Java on Ubuntu Linux. Thanks for reading this tutorial post. Visit our website thesecmaster.com and social media page on FacebookLinkedInTwitterTelegramTumblr, Medium & Instagram, and subscribe to receive updates like this.

You may also like these articles:

Arun KL

Arun KL is a cybersecurity professional with 15+ years of experience in IT infrastructure, cloud security, vulnerability management, Penetration Testing, security operations, and incident response. He is adept at designing and implementing robust security solutions to safeguard systems and data. Arun holds multiple industry certifications including CCNA, CCNA Security, RHCE, CEH, and AWS Security.

Recently added

Tutorials

View All

Learn More About Cyber Security Security & Technology

“Knowledge Arsenal: Empowering Your Security Journey through Continuous Learning”

Cybersecurity All-in-One For Dummies - 1st Edition

"Cybersecurity All-in-One For Dummies" offers a comprehensive guide to securing personal and business digital assets from cyber threats, with actionable insights from industry experts.

Tools

Featured

View All

Learn Something New with Free Email subscription

Subscribe

Subscribe