macOS切换jdk版本

macOS使用jenv切换jdk版本

官网:http://www.jenv.be/

jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable

安装

brew install jenv

自行查看Homebrew安装方式

配置

Bash和Zsh选其中一种,根据自己实际使用的shell工具决定。

Bash

echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

Zsh

echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc
source ~/.zshrc

添加JDK版本

jdk路径按自己实际安装路径为准

jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
oracle64-1.6.0.39 
added

jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home
oracle64-1.7.0.11 
added

设置版本

List managed JDKs

jenv versions
  system
  oracle64-1.6.0.39
* oracle64-1.7.0.11 (set by /Users/hikage/.jenv/version)

Configure global version

jenv global oracle64-1.6.0.39

Configure local version (per directory)

jenv local oracle64-1.6.0.39

Configure shell instance version

jenv shell oracle64-1.6.0.39

Search

    Table of Contents