安装Java:
brew cask install java //命令安装的是最新的Java9,我需要的是Java8……
卸载Java9:
ls /Library/Java/JavaVirtualMachines/ //查看jdk版本
//卸载
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk //此处9.0.1即是上一步查看到的版本号
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Java
安装Java8:
brew tap caskroom/versions
brew cask install java8
安装eclipse:
brew cask install eclipse-ide
配置Java环境变量:
/usr/libexec/java_home //定位JAVA_HOME位置
Matching Java Virtual Machines (1):
1.8.0_121, x86_64: "Java SE 8"
/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
vi ~/.zshrc //编辑profile文件
//按i键,输入以下代码
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
//然后按esc键,输入 :wq 保存并退出profile文件。
之后执行:
source ~/.base_profile
echo ~/.base_profile
查看环境变量是否配置成功:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home