找到~/.bash_profile 文件:
写入一下内容,开发中用到的所有环境比那里(包含java环境变量,android环境变量,gradle环境变量,NDK环境变量,cocos2dx环境变量,ant环境变量)
## ADD JAVA_VERSION #export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar # ADD ANDROID-SDK-ROOT export ANDROID_SDK_ROOT=/work/SDK/android-sdk-macosx export PATH=$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH # ADD Gradle export GRADLE_USER_HOME=/Users/duandazhi/.gradle/ export PATH=$GRADLE_USER_HOME/wrapper/dists/gradle-2.14.1-all/8bnwg5hd3w55iofp58khbp6yv/gradle-2.14.1/bin:$PATH # ADD Maven export M2_HOME=/Library/apache-maven-3.5.0 export PATH=$M2_HOME/bin:$PATH # Add environment variable COCOS_CONSOLE_ROOT for cocos2d-x COCOS_CONSOLE_ROOT=/work/Cocos2d-J/cocos2d-js-v3.6/tools/cocos2d-console/bin export PATH=$COCOS_CONSOLE_ROOT:$PATH # Add environment variable ANT_ROOT for cocos2d-x ANT_ROOT=/work/ant/apache-ant/bin export PATH=$ANT_ROOT:$PATH # Add environment variable NDK_ROOT for cocos2d-x NDK_ROOT=/work/NDK/android-ndk export PATH=$NDK_ROOT:$PATH # Add environment variable sunny_ngrok https://www.ngrok.cc/
保存文件,敲入命令, 输入命令以使
bash_profile
生效
$ source ~/.bash_profile
echo $M2_HOME
javac
java -v
mvn -v
android