Whenever I try to set my Java Home export JAVA_HOME=$(/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home)
in my .zshenv or .zshrc files, I get an /Users/{USER NAME HERE}/.zshenv:1: permission denied: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
error when starting up my terminal. In fact, I can't seem to be able to export anything (for example, export TEST=$(/Users/{USER NAME HERE})
gives me a zsh: permission denied: /Users/{USER NAME HERE}
error. I already gave full disk access in system preferences, but that doesn't seem to be working either. I am the only user on my computer.
The $(foo)
bit means, loosely, "run foo
as a program, then insert its output here and go on as if I had typed it", which is not what you want here. Just do
export JAVA_HOME=/Library/Java/...
The $()
bit is useful when you use the Mac's Java selection mechanism, and run e.g.
export JAVA_HOME=$(/usr/libexec/java_home -v16)
In that case, you're running a program, and setting JAVA_HOME
to the output of that program.
export
operation, you are doing something wrong, but it is hard to tell what. I suggest asking a new question, showing exactly what you did and what error message you got. However, there’s a risk it will be closed as off topic for Stack Overflow and more fit for one of the other sites. –
Religieux Ran into the same issue today, and figured out out to fix it. Remember to close/open your shell (or resource it) after making the change in your profile script.
In Z shell, the export statement is a bit different than bash, as you can set the environment variable without the $().
Instead of: export JAVA_HOME=$(/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home)
Use the simpler zsh form with quote marks for the path: export JAVA_HOME="/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home"
$()
does the same thing in both shells. –
Religieux Posting my fix in case it helps some else (or me the next time I run into this issue). This was done on a 2021 M1 Macbook Pro (Ventura 13.3.1 a) - if you're reading this in 2-3 years I hope this saves you some time.
I was running into this permission issue trying to get Expo's native module tutorial working (https://docs.expo.dev/modules/native-module-tutorial/) - iOS had its own issues with ruby/gem version chaos and with Android I had trouble with the above and when setting $JAVA_HOME I was running into the issue above - I wanted to configure the global version of JAVA so that Expo could build properly.
I managed to get past the error with JENV (https://www.jenv.be/) and using Android Studio to get a few versions of the JDK to play with (Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
) - you can easily download new Gradle JDKs here.
Openjdk Version 20 which is what I had installed previously (via brew) seemed to have compiler issues with expo's code so I installed Corretto v17 (via Android Studio). In Android Studio I could see the Home directory of this JDK so I was able to add it to the available versions to JENV (jenv add ~~~jdk home directory here~~~
) and then set that as the global version jenv global 17
- from there the $JAVA_HOME issues seemed to be resolved as the compiler was able to find and use the correct version.
In my case, I solved this problem by changing:
export JAVA_HOME=$(/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home) export JAVA_HOME=$(/usr/libexec/java_home)
to:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home export JAVA_HOME=/usr/libexec/java_home
- deleting the
$()
that encloses the values of the variables
PD: You can get this file by writing in the console(iTerm at Mackbook Pro m3 in my case):
nano ~/.zshrc
After deleting the $()
safe the file and run in the terminal:
source ~/.zshrc
© 2022 - 2024 — McMap. All rights reserved.