Java Mac配置Java环境变量

  |  
阅读次数
  |  
字数 186
  |  
时长 ≈ 1 分钟

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

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

1)首先确保已经安装了jdk

1
2
3
4
5
## check the present running java
which java

## check java version
java -version

2)以zsh为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 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