Java Installation on Linux (WSL) - Command
Descriptions
wsl --install
Installs Windows Subsystem for Linux (WSL) along with the default Linux distribution (Ubuntu if not
specified). Enables Linux to run natively inside Windows without VirtualBox/VMware. Run in
PowerShell as Administrator.
sudo apt update
Updates the package index on Ubuntu so you can download the latest versions of software.
Connects to Ubuntu’s repository servers and fetches the latest list of available packages.
sudo apt install openjdk-8-jdk -y
Installs the Java Development Kit (JDK) version 8, including compiler (javac) and runtime (java).
The -y flag automatically confirms the installation without prompting.
sudo apt install openjdk-11-jdk -y
Installs Java Development Kit (JDK) version 11. Similar to the above, but for version 11.
java -version
Checks if Java is installed and shows the installed version along with build details.
nano ~/.bashrc
Opens the .bashrc file in the Nano text editor. This file contains shell configuration commands that
run every time you start a terminal.
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
Defines the Java installation directory path as an environment variable JAVA_HOME, allowing
applications to locate Java.
export PATH=$JAVA_HOME/bin:$PATH
Adds Java’s bin directory to your PATH, enabling you to run Java commands like java and javac
from anywhere without specifying the full path.
source ~/.bashrc
Reloads the .bashrc file so that changes to environment variables take effect immediately without
restarting the terminal.
echo $JAVA_HOME
Prints the current value of the JAVA_HOME environment variable to confirm it’s set correctly.