如何在Mac OS 10.15.6中永久设置环境变量?

huangapple go评论84阅读模式
英文:

How to set environment variables permanently in Mac OS 10.15.6?

问题

我已经尝试了所有我能在网上找到的方法,但它们都不起作用。

我想要永久设置JAVA_HOMEPATH环境变量,以便在IntelliJ中我可以执行像“mvn”这样的命令。

我已将我的脚本写入.bash_profile,如下所示:
screenshot

但在我重新启动Mac并输入echo $JAVA_HOME之后,输出仍然是空的。

我还尝试了launchd.conf,如在这个答案中所说,但它也没有起作用。

有人可以在这里帮助我吗?
提前感谢!

英文:

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!

答案1

得分: 3

在 macOS 中,在你的 ~/.profile 文件中添加以下内容,如果你使用 zsh,请在 ~/.zshrc 文件中添加:

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

重新启动你的终端,或者直接应用你的更改:

source ~/.profile

如果你想了解更多相关信息,请参考这个链接,同时也可以参考这个链接以了解关于 Amazon Corretto 8 的安装过程。

如果你使用 zsh,你可以在 ~/.zprofile 文件中导入 .profile 的配置:

emulate sh
. ~/.profile
emulate zsh
英文:

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

答案2

得分: 1

Check your environment variables with:

env

then check if your config files are in the right directory. Read /etc/profile, for example:

nano /etc/profile

There you can find the path to the bashrc file.

英文:

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

huangapple
  • 本文由 发表于 2020年8月28日 02:17:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63622010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定