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