DEV Community

slatzz
slatzz

Posted on

How To: JAVA_HOME (Mac)

Table of Contents

  1. Check current version
  2. View all versions on machine
  3. Download a new version of Java
  4. Check JAVA_HOME
  5. Update JAVA_HOME
    1. Step one
    2. Step two

Check current version

java -version
Enter fullscreen mode Exit fullscreen mode

Image description


View all versions on machine

/usr/libexec/java_home -V
Enter fullscreen mode Exit fullscreen mode

Image description


Download a new version of Java


Check JAVA_HOME

echo $JAVA_HOME
Enter fullscreen mode Exit fullscreen mode

Update JAVA_HOME

Step one

export JAVA_HOME=`/usr/libexec/java_home -v X.X.X`

// Example
export JAVA_HOME=`/usr/libexec/java_home -v 20.0.02`
Enter fullscreen mode Exit fullscreen mode

Step two

nano ~/.zshrc

/**
* If you don't already have JAVA_HOME defined, add it
* to this file with the path to your desired version of 
* Java. Example below:
**/

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home"
Enter fullscreen mode Exit fullscreen mode

Save your changes

CTRL + O (Not zero)
ENTER
CTRL + X

Confirm

// Confirm your file saved
nano ~/.zshrc

// Confirm Java version
java --version
Enter fullscreen mode Exit fullscreen mode

Thank you for reading 🙏🏽 I hope this was helpful. ☺️

Top comments (0)