安装 jenv
https://github.com/jenv/jenv
配置
# Shell: bash
❯ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
❯ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
# Shell: zsh
❯ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
❯ echo 'eval "$(jenv init -)"' >> ~/.zshrc
❯ echo ". <(jenv init -)" >> ~/.zshrc
验证
jenv doctor
安装 JAVA
安装最新版JAVA
❯ brew install java
❯ sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
❯ jenv add "$(/usr/libexec/java_home)"
安装JAVA8
❯ brew install openjdk@8
❯ sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk
❯ jenv add /Library/Java/JavaVirtualMachines/openjdk-8.jdk/Contents/Home/
安装JAVA11
❯ brew install openjdk@11
❯ sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
❯ jenv add /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home/
安装JAVA17
❯ brew install openjdk@17
❯ sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
❯ jenv add /Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/
切换JAVA版本
查看已安装版本
jenv versions
设置全局 Java 版本:
jenv global 1.8
设置局部(项⽬级)Java 版本:
jenv local 11.0 1
设置 Shell 级 Java 版本:
jenv shell 11.0
网友评论