Before installing Java, make sure your system is up to date with the latest package versions.
sudo apt update
sudo apt upgrade -y
Go to the Oracle Java SE website to download the desired version.
Note
If you have a Raspberry Pi, download the ARM 64-bit version of Java.
Tip
You can also use wget
to download the file directly from the terminal.
Example:
wget https://download.oracle.com/java/XX/latest/jdk-XX_linux-aarch64_bin.tar.gz
Extract the downloaded archive into a temporary directory.
tar -xvzf jdk-XX_linux-aarch64_bin.tar.gz
Move the contents of the extracted folder to /usr/local/
for centralized management of binaries and libraries.
sudo mv jdk-XX /usr/local/
Next, create a symbolic link for the java
binary in /usr/local/bin
so that it is easily accessible from any terminal without specifying the full path.
sudo ln -s /usr/local/jdk-XX/bin/java /usr/local/bin/java
Note
This command makes the java
binary globally available as a command. You can now use it directly.
Although the symbolic link makes Java accessible, it's often useful to define the JAVA_HOME
variable.
export JAVA_HOME=/usr/local/jdk-21
export PATH=$JAVA_HOME/bin:$PATH
Then, reload the configuration file with:
source ~/.bashrc
To verify that Java is correctly installed and that version 21 is used by default, run the following command:
java -version
Note
This should display something similar to:
java version "XX"
Java(TM) SE Runtime Environment (build XX+XX-XXXX)
Java HotSpot(TM) 64-Bit Server VM (build XX+XX-XXXX, mixed mode)