1、打开.bash_profile文件添加一个函数
#add a function for switch idk version.
function jdkset() {
if [ $# -ne 0 ]; then
removeFromPath ‘/System/Library/Frameworks/JavaVM.framework/Home/bin‘
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v [email protected]`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
2、重启terminal, jdkset 1.6.0 就ok了
时间: 2024-10-13 07:51:54