0x00
本文主要记录mac上jenv管理多版本java的坑;
前提是配置好brew镜像,确保brew update会正常执行而不是卡住。
0x01 安装jenv
brew install jenv
# 添加jenv环境变量,修改用户文件夹下对应的~/.bash_profile或者~/.zhsrc export PATH="$HOME/.jenv/bin:$PATH" eval "$(jenv init -)"
# 如果遇到类似报错, xxxx/.jenv/versions/openjdk64-1.8.0.422: No such file or directory,直接mkdir xxxx/.jenv/versions/ 覆盖该文件夹,或者先先删除再覆盖
0x02 安装多版本java
brew install openjdk@8 brew install openjdk@11 brew install openjdk@21
# 检查java是否安装完成 brew list | grep openjdk # brew安装的java的路径 ls -l /usr/local/Cellar | grep openjdk
0x03 /Library/Java/JavaVirtualMachines/
# 创建软连接到/Library/Java/JavaVirtualMachines/ 方便软件检测和使用 sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk sudo ln -sfn /usr/local/opt/openjdk@21/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk
0x04 使用jenv管理java
jenv add /Library/Java/JavaVirtualMachines/openjdk-8.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home
0x05 使用jenv指定java
# 查看可用java jenv versions # 全局 jenv global 21 # 当前目录 jenv local 21 # 验证当前java版本 java -version
标签:java,jdk,openjdk,jenv,Java,mac,JavaVirtualMachines,JAVA From: https://www.cnblogs.com/JetpropelledSnake/p/18519724