Home > Back-end >  Permission Error When Exporting to $JAVA_HOME on MacOS Big Sur
Permission Error When Exporting to $JAVA_HOME on MacOS Big Sur

Time:09-17

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.

CodePudding user response:

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.

  • Related