Mac 下配置Java环境变量及Maven环境变量

时间:2022-12-11 23:02:32

一、官网下载MAC版本的JDK,这里用的jdk版本是 1.7,得到jdk-7u79-macosx-x64.dmg,双击直接默认安装,默认安装路径是

/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk


二、下载Maven,这里用的Maven版本是3.0.5,放到指定目录,我的目录是/Users/longwnetao/java/apache-maven-3.0.5


三、在用户根目录下,输入如下命令编辑.bash_profile文件

cd ~

vi .bash_profile(文件不存在则新建)


在文件中输入以下内容

#JDK安装目录,一定要指定到Contents/Home

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home"

#Maven存放路径

MAVEN_HOME="/Users/longwentao/java/apache-maven-3.0.5"

export MAVEN_HOME

export JAVA_HOME

export PATH=${PATH}:${MAVEN_HOME}/bin:${JAVA_HOME}/bin


按esc键退出编辑模式,输入wq保存退出编辑


输入source .bash_profile命令,使.bash_profile文件生效


输入java -version命令,验证JDK的安装结果,出现如下结果,证明安装成功

longwentaodeMacBook-Pro:java longwentao$ java -version

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)


输入man -v命令,验证Maven安装结果,出现如下结果,证明安装成功

longwentaodeMacBook-Pro:java longwentao$ mvn -v

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 21:51:28+0800)

Maven home: /Users/longwentao/java/apache-maven-3.0.5

Java version: 1.7.0_79, vendor: Oracle Corporation

Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre

Default locale: zh_CN, platform encoding: UTF-8

OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"