您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页Mac上设置Java环境变量

Mac上设置Java环境变量

来源:二三娱乐

说明

  1. 如果是用bash,修改/.bash_profile或/.profile。
    两者的区别:
    .bash_profile是用户级别的,更新系统或切换用户就会失效。
    .profile是系统级别的,永远都有效。
    2.如果是用zsh,修改~/.zshrc。

step1:检查是否安装了jdk(Mac系统默认已安装)

1.查看java的安装路径
which java
2.查看java版本
java -version

step2:设置环境变量

以bash为例:
## edit .bash_profile to set java_home variable
vim ~/.bash_profile

## add the following line into the file
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home 
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

## let the configuration in .bash_profile take effect
source .bash_profile

以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

<h3>The End:</h3>

  1. 我的:
  2. 我的:
  3. 我的:
  4. 我的:
  5. Email:
  6. 微信:


    扫一扫上面的二维码,加我微信

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务