Other languages

Switch the default Java version

Choose which installed Java (JDK) your terminal and tools use.

Fill these in once
  1. List the Java versions you have
    Terminal
    /usr/libexec/java_home -V
  2. Use one by default
    Terminal
    echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 21)' >> ~/.zshrc
    source ~/.zshrc

Check it worked

  1. Check the version
    Terminal
    java -version
  1. Pick the default Java from a listNeeds sudo
    Terminal · Ubuntu / Debian
    sudo update-alternatives --config java

    Type the number of the version you want.

Check it worked

  1. Check the version
    Terminal · Ubuntu / Debian
    java -version
  1. List the Java versions you have
    PowerShell
    Get-ChildItem "C:\Program Files\Eclipse Adoptium"
  2. Point JAVA_HOME at the one you want
    PowerShell
    [Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Eclipse Adoptium\jdk-21", "User")

    Close and reopen PowerShell afterwards.

Check it worked

  1. Check JAVA_HOME
    PowerShell
    $env:JAVA_HOME