Search code examples
javamacoszshjava-home

Setting JAVA_HOME in zshrc on M1 Mac?


When I use

/usr/libexec/java_home

I get

/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home

but I want to be getting

/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home

I've changed my .zshrc file a number of times and it seems to always revert to the default of temurin 17.

My application will not run android pointing to temurin 17 and it should be selecting zulu 11 jdk.


Solution

  • One thing you should do after changing .zshrc file is to execute:

    source ~/.zshrc in order for the changes in your .zshrc to be activated


    But I would suggest when working with multiple java version, to setup alias and be able to easily change versions on-demand.

    You can find a guide for this on this Stackoverflow answer: https://stackoverflow.com/a/40754792/2352196