mac設置java環境變量, 使用oh-my-zsh


參考:http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/

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

如果用zsh,修改~/.zshrc

修改這些文件之后,重修打開terminal,配置不會丟

 

首先確保已經安裝了jdk:

## check the present running java
which java

## check java version
java -version

 

以zsh為例:

 1 ## check all the available jdk
 2 /usr/libexec/java_home -V
 3 
 4 ## check the top jdk
 5 /usr/libexec/java_home
 6 
 7 ## check some jdk (eg. version 1.7)
 8 /usr/libexec/java_home -v 1.7
 9 
10 ## edit .zshrc to set java_home variable
11 vim ~/.zshrc
12 
13 ## add the following line into the file
14 export JAVA_HOME=$(/usr/libexec/java_home)
15 
16 ## you can also use the following line to set the variable, which is not recommended, only for older mac os.
17 ## export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
18 
19 ##let the configuration in .zshrc take effect
20 source ~/.zshrc
21 
22 ## check if configure succeed
23 echo $JAVA_HOME

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM