Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The java version in "mvn -version" is different from the version in "java -version" for mac

JAVA VERSION

JAVAVERSION

As the screenshot shows, the java version is different, how can I change the java version in maven to 1.8?

like image 979
Alex Avatar asked Feb 13 '26 11:02

Alex


1 Answers

Few things to debug

  1. Please check for the cat /usr/local/Cellar/maven/3.6.3_1/bin/mvn (maven uses this if present) - not sure if this has anything with homebrew installed maven. If there are any hardcoded versions, it might cause a difference in behavior.
  2. echo $JAVA_HOME (maven uses this path and complains if not found)
  3. did you set JAVA_HOME explicitly in any of the terminal sessions?

Also, how did you install java and maven? are they both installed using homebrew?

Additional info

  1. the following alias will help to switch between java versions easily
alias java11="export JAVA_HOME=`/usr/libexec/java_home -v 11`"
alias java8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`"
  1. this can be added to .bashrc or .zshrc
like image 199
Thiyanesh Avatar answered Feb 15 '26 23:02

Thiyanesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!