mac zsh环境配置java_home环境变量

用zsh,修改~/.zshrc

修改这些文件之后,重修打开terminal,配置不会丢

 

首先确保已经安装了jdk:

## check the present running java
which java

## check java version
java -version

 

以zsh为例:

## check all the available jdk
/usr/libexec/java_home -V

## check the top jdk
/usr/libexec/java_home

## check some jdk (eg. version 1.7)
/usr/libexec/java_home -v 1.7

## edit .zshrc to set java_home variable
vim ~/.zshrc

## add the following line into the file
export JAVA_HOME=$(/usr/libexec/java_home)

## you can also use the following line to set the variable, which is not recommended, only for older mac os.
## export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

##let the configuration in .zshrc take effect
source ~/.zshrc

## check if configure succeed
echo $JAVA_HOME

 

如果用bash,修改~/.bash_profile 或 ~/.profile;

 

 

 

 

 

参考:http://www.cnblogs.com/hf-cherish/p/5603147.html

posted @ 2017-08-08 16:21  ctgu_czy  阅读(669)  评论(0编辑  收藏