Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission Error When Exporting to $JAVA_HOME on MacOS Big Sur

Tags:

java

macos

zsh

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.

like image 585
user16925173 Avatar asked Feb 18 '26 15:02

user16925173


2 Answers

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.

like image 65
Ture Pålsson Avatar answered Feb 20 '26 05:02

Ture Pålsson


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"

like image 44
Tomm Matthis Avatar answered Feb 20 '26 05:02

Tomm Matthis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!