How to Install Java on Ubuntu in 2025: A Friendly Guide

Hey there! Want to get Java running on your Ubuntu server? You’ve got this. Whether you’re setting up a VPS with CreativeON or just experimenting at home, this step-by-step guide will help you install Java without any fuss. Let’s dive in!

Why Install Java on Ubuntu?

Java is one of the most popular programming languages out there. It powers everything from Minecraft servers to Spring Boot apps and even parts of Google Workspace add-ons. If you’re running a VPS hosting plan in Pakistan, having Java installed means you can:

  • Run custom applications

  • Host Java-powered websites

  • Test or build coding projects

Pretty neat, right?

What You’ll Need

Before we start, make sure you have:

  • An Ubuntu machine or VPS (works on Ubuntu 20.04, 22.04, or 24.04 LTS)

  • A user account with sudo rights

  • Internet access to download packages

💡 If you already picked a VPS from CreativeON, you’re off to a great start—we provide reliable servers in Pakistan backed by friendly support and affordable pricing.

Step-by-Step: Installing Java

1. Update Your Package List

First, update your system so Ubuntu knows about the latest packages:

sudo apt update

 

2. Install OpenJDK

OpenJDK is the free, open-source version of Java. The recommended long-term support (LTS) release in 2025 is Java 21. To install it, run:

sudo apt install openjdk-21-jdk

 

👉 If you prefer, you can swap 21 with 17 or 11 for other versions.

3. Verify the Installation

Check if Java installed correctly:

java -version

 

You should see something like:

openjdk version “21.0.2” 2025-01-15

 

4. Set Your Default Java (Optional)

If you have more than one Java version, choose which one Ubuntu should use:

sudo update-alternatives –config java

 

Select the version number you want as the default.

Real-Life Uses You Can Try Today

Now that Java is installed, here are a few things you can do right away:

  • Run a Minecraft Server on your VPS and invite friends.

  • Deploy a Spring Boot App to test your own web services.

  • Automate Tasks with Java programs, such as file backups or log management.

Common Questions

Go with Java 21 (latest LTS) for most projects. Java 17 is also widely used and stable.

JRE (Java Runtime Environment) is for running Java programs. JDK (Java Development Kit) includes everything you need to run and build Java applications.

Yes! The steps are the same whether you’re on cloud hosting, a VPS, or a dedicated server.

Helpful Tips

  • Keep Java Updated – Run sudo apt update && sudo apt upgrade regularly.

  • Check Disk Space – Make sure your server has at least 1 GB free.

  • Use Trusted Sources – Always install Java from official repositories for security.

Optional: Use Snap – You can also run:

sudo snap install openjdk –classic

  •  But apt is the easiest method.

Summary

  • Update your package list (sudo apt update).

  • Install Java 21 (sudo apt install openjdk-21-jdk).

  • Verify installation (java -version).

  • (Optional) Switch defaults with update-alternatives.

And that’s it—you now have Java running on your Ubuntu server! From hosting a Minecraft server to deploying web apps, the possibilities are endless.

If you’re looking for a reliable VPS in Pakistan, CreativeON has you covered—with responsive support, .PK domain expertise, and affordable hosting plans.

Table of Contents