echo $JAVA_HOME在MacOS Catalina中返回空白,尽管在zshrc中已正确设置。

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

echo $JAVA_HOME returns blank in MacOS catalina despite having set it properly in zshrc

问题

我正在使用最新的MacOS Catalina(10.15.4),并且在我的配置文件中使用.zshrc作为最新版本的Mac已弃用bash shell。这是我之前关于无法使用jenv将默认的Java版本更改为1.8的问题的后续问题

在我尝试进行更多调试时,发现我的echo $JAVA_HOME始终返回空白,尽管我已经按照以下方式设置了它。

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

以及

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

注意:在更改后,我已经在终端中加载了我的.zshrc文件,但是仍然没有成功,尽管在终端中设置后它会打印出正确的值,但这仅限于该终端(预期的行为)。

添加我~/.zshrc的内容如下:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
#export JAVA11_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
#export JAVA14_HOME=$(/usr/libexec/java_home -v14)
#export RUNTIME_JAVA_HOME=$(/usr/libexec/java_home -v11)
export PATH=$JAVA_HOME/bin:$PATH
#export PATH="/Users/java-dev/Library/Python/3.7/bin/:$PATH"
export PATH=/usr/local/bin:$PATH
export PATH=/usr/bin:$PATH
alias sr='source ~/.zshrc'
alias rt='cd /Users/java-dev/rt'
alias dev='cd /Users/java-dev/development'
alias code='cd /Users/java-dev/code'
英文:

I a using the latest MacOS catalina(10.15.4) and using .zshrc for my profile as latest version of mac deprecated the bash shell, This is the follow-up question of my previous unanswered question on not able to change the default java version to 1.8 using jenv.

When I was trying to debug more found my echo $JAVA_HOME always returns blank, despite having set it in following manner.

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

And

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

Note i've sourced my .zshrc file after the change but still no luck, although when I set on the terminal then it print the proper value but its only on that console(as expected).

Adding the content of my ~/.zshrc

export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
#export JAVA11_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
#export JAVA14_HOME=$(/usr/libexec/java_home -v14)
#export RUNTIME_JAVA_HOME=$(/usr/libexec/java_home -v11)
export PATH=$JAVA_HOME/bin:$PATH
#export PATH="/Users/java-dev/Library/Python/3.7/bin/:$PATH"
export PATH=/usr/local/bin:$PATH
export PATH=/usr/bin:$PATH
alias sr='source ~/.zshrc'
alias rt='cd /Users/java-dev/rt'
alias dev='cd /Users/java-dev/development'
alias code='cd /Users/java-dev/code'

答案1

得分: 1

文件名在最新的Catalina操作系统中已更改。您需要创建一个名为**.zprofile**的文件(与您创建.bash_profile文件的位置相同)。这需要这样做是因为.bash_profile现在变成了.zprofile,然后将您的导出命令放在那里。

如果它已经存在,请像下面这样在文件中追加您的导出命令。

export PATH=$your_path$:$PATH
export JAVA_HOME=$your_path$
export M2_HOME=$your_path$

查看这个链接:https://stackoverflow.com/questions/56784894/macos-catalina-10-15beta-why-is-bash-profile-not-sourced-by-my-shell

英文:

The file name is changed in latest catalina OS . you need to create a file named .zprofile (same place where you have created .bash_profile file. This needs to be done because .bash_profile is now .zprofile) and place your export command over there.

If it already exists, please append your export command in the file like below.

export PATH=$your_path$:$PATH

export JAVA_HOME=$your_path$

export M2_HOME=$your_path$

check this <https://stackoverflow.com/questions/56784894/macos-catalina-10-15beta-why-is-bash-profile-not-sourced-by-my-shell>

huangapple
  • 本文由 发表于 2020年5月29日 14:44:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/62080159.html
匿名

发表评论

匿名网友

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

确定