简体   繁体   中英

How can I change the JAVA_HOME directory permanently on MAC?

I have a problem with my JAVA_HOME directory. Every time I want to use gradle I need to set my JAVA_HOME directory again and again.

I know how to export it to the right directory but after I close my terminal, I have to do it all over again.

What I do is

which java --> /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/bin/java

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/"

to set the correct path. Everything is then set correctly, but when I close the terminal and get check the path again:

echo $JAVA_HOME -> /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Homeexport

Can you guys tell me how to change the directory permanently? I googled so often and found solutions which didn't help me at all

This isn't so much a Gradle question, as an environment question. You would need to set JAVA_HOME in your shell's configuration. If you can tell me what shell you're using, I can point you in the right direction.

Since you're using ZSH, you can open ~/.zshenv and paste this in:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/"

Another solution would be to use something like Jenv to manage your Java environment, with the Gradle plugin enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM