Install Java JDK on Linux or MacOS

This article explains the steps involved to install Java JDK on Linux or MacOS.

Get the architecture of the Machine from Terminal using:

uname -m

Create a directory for installation:

mkdir -p $HOME/tools/java

Download latest java LTS binary:

Download java 25 binary for Linux / Mac OS operating system with the correct architecture type to directory $HOME/tools/java

Download URL https://adoptium.net/en-GB/temurin/releases?mode=filter&os=any&arch=any

Extract and rename java binary:

find $HOME/tools/java -type f -name OpenJDK25*.tar.gz | xargs -I {} mv {} $HOME/tools/java/OpenJDK25.tar.gz

tar -xvzf $HOME/tools/java/OpenJDK25.tar.gz -C $HOME/tools/java

find $HOME/tools/java -type d -name jdk-25* | xargs -I {} mv {} $HOME/tools/java/jdk-25

Make the extracted binaries as executables:

chmod a+rwx -R $HOME/tools/java/*

Identify the shell used in the Terminal using:

echo $SHELL

Configure PATH:

Add the following lines to $HOME/.bash_profile or $HOME/.bashrc or $HOME/.zprofile based on the shell used by the Terminal and the changes will take effect after system restart

# setting java homes

export JAVA_25_HOME=$HOME/tools/java/jdk-25

export JAVA_HOME=$JAVA_25_HOME

export PATH=$JAVA_25_HOME/bin:$PATH

Temporarily source the changes:

source $HOME/.bash_profile

or

source $HOME/.zprofile

Verify default java version:

java -version

Setup IDE SDK:

In the IDE (IntelliJ) add the SDK location as $HOME/tools/java/jdk-25


Comments

Popular posts from this blog

Export/Backup Ollama Model

JSON with curl and jq

Import self signed in Linux for Chrome / Chromium headless testing