Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Last active August 29, 2022 19:39
Show Gist options
  • Save tangoabcdelta/6bc02632dbf3f2252f208564ed782a6e to your computer and use it in GitHub Desktop.
Save tangoabcdelta/6bc02632dbf3f2252f208564ed782a6e to your computer and use it in GitHub Desktop.
How to set path to $JAVA_HOME in environment variable correctly in Mac OS (new and old - zsh and bash, both)
# For newer Mac OS versions where zsh is the default terminal
$ nano ~/.zshenv
# For older Mac OS versions where bash is the default terminal
$ nano ~/.bash_profile
# add the following two entries in ~/.zshenv
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=/correct/path/to/apache-maven-3.8.6/bin:$PATH
# save and exit
# and then source it
# NEW
$ source ~/.zshenv
# OLD
$ source ~/.bash_profile
# now run the following to test
$ mvn -version
# Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
# Maven home: /correct/path/to/apache-maven-3.8.6
# Java version: 17.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home
# Default locale: en_IN, platform encoding: US-ASCII
# OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
# run clean-install
$ mvn clean install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment