How to Install Java 21 on Linux | Set JAVA_HOME | Run JShell (2026)

Published: 01 February 2026
on channel: Developer_Aid
52
like

In this video, you will learn how to install OpenJDK 21 (LTS) on Ubuntu Linux, set the JAVA_HOME environment variable correctly, and run your first Java program using JShell.
This guide is step-by-step with on-screen text (no voice) and is perfect for beginners setting up Java for development, IDEs, Maven, or Gradle.

💻 Commands used in this video:
1) Check if Java is installed
java --version

2) Enable universe repository & Update
sudo add-apt-repository universe

3) Install OpenJDK 21 (JDK)
sudo apt install openjdk-21-jdk

4) Verify Java and Javac installation
clear
java --version
javac --version

5) Install Nano Editor (if not installed)
sudo apt install nano

6) Open Configuration File
nano ~/.bashrc

7) Set Environment Variables
Scroll to the bottom of the file using the arrow keys and paste these two lines:

export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$JAVA_HOME/bin:$PATH

To Save & Exit Nano:
Press Ctrl + O then Enter (to save)
Press Ctrl + X (to exit)

8) Reload Configuration & Verify Path

source ~/.bashrc
echo $JAVA_HOME

9) Run First Java Program (JShell)
jshell

Inside JShell, type:

System.out.println("Hello Java 21");

To exit JShell:
/exit

✅ Result:
Your Ubuntu system is now ready for:
Java Development
IDEs (IntelliJ IDEA / VS Code)
Build tools like Maven / Gradle

#java #linux #Ubuntu #Java21 #OpenJDK #Programming #Coding #Tutorial #NoVoice


On this page of the site you can watch the video online How to Install Java 21 on Linux | Set JAVA_HOME | Run JShell (2026) with a duration of hours minute second in good quality, which was uploaded by the user Developer_Aid 01 February 2026, share the link with friends and acquaintances, this video has already been watched 52 times on youtube and it was liked by like viewers. Enjoy your viewing!