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

我的未来我决定 提交于 2020-06-17 15:47:55

问题


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:


Had a look at your .zshrc content and looks like issue is happening due to your Jenv which changed the java versions based on directory and might have messed up your JAVA_HOME.

Can you try removing these line and try again.

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"



回答2:


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 macOS Catalina 10.15(beta) - Why is ~/.bash_profile not sourced by my shell?



来源:https://stackoverflow.com/questions/62080159/echo-java-home-returns-blank-in-macos-catalina-despite-having-set-it-properly-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!