Skip to content

Instantly share code, notes, and snippets.

@HallexCosta
Last active February 26, 2025 16:57
Show Gist options
  • Save HallexCosta/32bfa9477056f0590a29d8407fc8d6c6 to your computer and use it in GitHub Desktop.
Save HallexCosta/32bfa9477056f0590a29d8407fc8d6c6 to your computer and use it in GitHub Desktop.
Configuring Java JDK in your Ubuntu

Requeriments

Guide

Note

Change the jdk.gz filename or folder name, based in your verion JDK downloaded as example I use the jdk-20.0.1

Preparing Artefacts

  1. Access the official JDK website and Download a version available or compatible with your project
  2. Extract with tar -xvf jdk-20.0.1.tar.gz
  3. Move extracted foldersudo mv jdk-20.0.1 /opt/

Configuring global binaries

  1. Create symbolic link appointing to jdk binaries
sudo ln -s /opt/jdk-20/bin/java /usr/bin/java
sudo ln -s /opt/jdk-20/bin/javac /usr/bin/javac
  1. Or configure manually the env variable JAVA_HOME in $HOME/.config/config.fish
set -x JAVA_HOME /opt/jdk-20.0.1
set -x PATH $JAVA_HOME/bin $PATH

Important

If your default shell is zsh or bash, is need change the syntax and edit the respectives files .zshrc or .bashrc

  1. Reload shell source $HOME/.config/config.fish
# zsh
source $HOME/.zshrc

# bash
source $HOME/.bashrc
  1. Test java -version

Output:

openjdk version "20.0.1" 2023-04-18
OpenJDK Runtime Environment (build 20.0.1+9-29)
OpenJDK 64-Bit Server VM (build 20.0.1+9-29, mixed mode, sharing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment