How to set environment variables permanently in Mac OS 10.15.6?

Viewed 7939

I have tried all approaches I can find online, but none of them works.

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

I have written my script into .bash_profile as shown below: screenshot

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

I also tried launchd.conf as said in this answer, but it didn't work either.

Could someone help me here? Thanks in advance!

2 Answers

For osx add this in your ~/.profile or if you are using zsh inside ~/.zshrc

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

restart your terminal or simply apply your changes

source ~/.profile

refer this to know more about related to this question & also refer this to know more about installation process of Amazon Corretto 8.

If you are using zsh you can import .profile config inside ~/.zprofile

emulate sh
. ~/.profile
emulate zsh

Check your enviroment variables with

env 

then check if your config files are in the right directory. Read /etc/profile e.g.

nano /etc/profile

There can you find the path to bashrc file

Related