0

I am trying to set my machines javac version to 11 from 18.0.2 and I'm doing the following steps

  1. open ~/.zshenv
  2. export JAVA_HOME=$(/usr/libexec/java_home -v11)
  3. source ~/.zshenv

When I check the version, I still get it as 18.0.2. Not sure what I am doing wrong here. Could someone please help me with this? Been stuck on this forever.

E_net4
  • 27,810
  • 13
  • 101
  • 139
boomchickawawa
  • 508
  • 1
  • 6
  • 25
  • 2
    You might also want to ask this on [AskDifferent](https://apple.stackexchange.com/) – Stephen P Oct 28 '22 at 20:05
  • Check your PATH variable or try where is javac. Sounds like the path is pointing to the v18 executable. – kiwiron Oct 28 '22 at 20:14
  • @kiwiron `echo $PATH` returns this `/Users/xxx/bin:/usr/local/bin:/Users/xxx/bin:/usr/local/bin:/usr/local/bin:/Users/xxx/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/Users/xxx/bin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin` – boomchickawawa Oct 28 '22 at 20:24
  • 1
    By the way, a suggestion: https://sdkman.io/ – Basil Bourque Oct 28 '22 at 21:43

3 Answers3

1

What works like a charme for me is using jenv: https://www.jenv.be/

With jenv you can also switch between different Java versions.

Before using jenv, I relied on the Maven toolchains plugin: https://maven.apache.org/plugins/maven-toolchains-plugin/

Thus, I actually never really worried about JAVA_HOME on MacOS. Maybe one of these options also is an alternative for you.

Andreas Siegel
  • 1,050
  • 8
  • 9
0
export JAVA_HOME=`/usr/libexec/java_home -v 11` 
harry-potter
  • 1,981
  • 5
  • 29
  • 55
0

I don't know if this typo is only in your question here, but you need to put a space between "-v" and "11":

export JAVA_HOME=$(/usr/libexec/java_home -v 11)
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 19 '23 at 08:16