Java – How do I set environment variables permanently in Mac OS 10.15.6?

How do I set environment variables permanently in Mac OS 10.15.6?… here is a solution to the problem.

How do I set environment variables permanently in Mac OS 10.15.6?

I

tried everything I could find online, but to no avail.

I

want to permanently set the JAVA_HOME and PATH environment variables so that in IntelliJ I can issue commands like “mvn”.

I’ve written the script into .bash_profile like this:
screenshot

But after I restart my Mac and issue echo $JAVA_HOME, the output is still empty.

I also tried launchd.conf answer, but it is also useless.

Can someone help me?
Thanks in advance!

Solution

For osx, add this to your ~/.profile or if you use zsh in ~/.zshrc

export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home

Restart your terminal or simply apply your changes

source ~/.profile

Quotethis Learn more about this issue
& also quote this to learn more about the installation process for Amazon Corretto 8.

If you are using zsh, you can import the .profile configuration in ~/.zprofile

emulate sh
. ~/.profile
emulate zsh

Related Problems and Solutions