Mac 4步 安装 Jenv 管理多版本JDK

1、安装 Jenv

复制代码
TsengdeMacBook-Pro:~ zeng$ brew install jenv
==> Auto-updating Homebrew...
Adjust how often this is run with `$HOMEBREW_AUTO_UPDATE_SECS` or disable with
`$HOMEBREW_NO_AUTO_UPDATE=1`. Hide these hints with `$HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
aiac: Artificial Intelligence Infrastructure-as-Code Generator
anyzig: Universal zig executable that runs any version of zig
apache-polaris: Interoperable, open source catalog for Apache Iceberg
cogapp: Small bits of Python computation for static files
electric: Real-time sync for Postgres
entt: Fast and reliable entity-component system for C++
flexget: Multipurpose automation tool for content
glom: Declarative object transformer and formatter, for conglomerating nested data
go-passbolt-cli: CLI for passbolt
go@1.24: Open source programming language to build simple/reliable/efficient software
goodls: CLI tool to download shared files and folders from Google Drive
influxdb@2: Time series, events, and metrics database
limine: Modern, advanced, portable, multiprotocol bootloader and boot manager
mk: Wrapper for auto-detecting build and test commands in a repository
msolve: Library for Polynomial System Solving through Algebraic Methods
nessie: Transactional Catalog for Data Lakes with Git-like semantics
oasis: CLI for interacting with the Oasis Protocol network
omnara: Talk to Your AI Agents from Anywhere
qman: Modern man page viewer
quadcastrgb: Set RGB lights on HyperX QuadCast S and Duocast microphones
wgpu-native: Native WebGPU implementation based on wgpu-core

==> Fetching downloads for: jenv
==> Fetching jenv
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/jenv-0.5.9.all.bottle.tar.gz
################################################################################################## 100.0%
==> Pouring jenv-0.5.9.all.bottle.tar.gz
==> Caveats
To activate jenv, add the following to your shell profile e.g. ~/.profile
or ~/.zshrc:
  export PATH="$HOME/.jenv/bin:$PATH"
  eval "$(jenv init -)"
==> Summary
🍺  /usr/local/Cellar/jenv/0.5.9: 91 files, 100.8KB
==> Running `brew cleanup jenv`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
==> No outdated dependents to upgrade!
TsengdeMacBook-Pro:~ zeng$ 

2、配置 Jenv 生效

复制代码
TsengdeMacBook-Pro:~ zeng$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile 
TsengdeMacBook-Pro:~ zeng$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile 
TsengdeMacBook-Pro:~ zeng$ source ~/.bash_profile 
jenv has been updated, process to refresh plugin links
TsengdeMacBook-Pro:~ zeng$ jenv versions
* system (set by /Users/zeng/.jenv/version)
TsengdeMacBook-Pro:~ zeng$

3、添加 JDK 1.8.0_261

复制代码
/usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    1.8.261.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_261 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
    1.8.0_231 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
TsengdeMacBook-Pro:~ zeng$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
oracle64-1.8.0.261 added
1.8.0.261 added
1.8 added
TsengdeMacBook-Pro:~ zeng$ jenv versions
* system (set by /Users/zeng/.jenv/version)
  1.8
  1.8.0.261
  oracle64-1.8.0.261
TsengdeMacBook-Pro:~ zeng$ jenv global oracle64-1.8.0.261
TsengdeMacBook-Pro:~ zeng$
4、设置全局默认 JDK
复制代码
TsengdeMacBook-Pro:~ zeng$ jenv global oracle64-1.8.0.261
TsengdeMacBook-Pro:~ zeng$ java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
TsengdeMacBook-Pro:~ zeng$

安装 JDK21.0.8

复制代码
/usr/libexec/java_home -V
Matching Java Virtual Machines (4):
    21.0.8 (x86_64) "Oracle Corporation" - "Java SE 21.0.8" /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
    1.8.261.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_261 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
TsengdeMacBook-Pro:~ zeng$ jenv add /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
oracle64-21.0.8 added
21.0.8 added
21.0 added
21 added
TsengdeMacBook-Pro:~ zeng$ jenv versions
  system
  1.8
  1.8.0.261
  21
  21.0
  21.0.8
* oracle64-1.8.0.261 (set by /Users/zeng/.jenv/version)
  oracle64-21.0.8
TsengdeMacBook-Pro:~ zeng$

设置 JDK 21 为全局默认

复制代码
TsengdeMacBook-Pro:~ zeng$ jenv global oracle64-21.0.8
TsengdeMacBook-Pro:~ zeng$ jenv versions
  system
  1.8
  1.8.0.261
  21
  21.0
  21.0.8
  oracle64-1.8.0.261
* oracle64-21.0.8 (set by /Users/zeng/.jenv/version)
TsengdeMacBook-Pro:~ zeng$ java -version
java version "21.0.8" 2025-07-15 LTS
Java(TM) SE Runtime Environment (build 21.0.8+12-LTS-250)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.8+12-LTS-250, mixed mode, sharing)
TsengdeMacBook-Pro:~ zeng$

JDK 21 成为默认版本:

复制代码
jenv global oracle64-21.0.8

或者只在当前 shell 使用:

复制代码
jenv shell oracle64-21.0.8

或在某个项目中使用:

复制代码
cd /path/to/your/java21-project
jenv local oracle64-21.0.8  # 会生成 .java-version 文件

JDK17 免登录下载地址

Java Archive Downloads - Java SE 17.0.12 and earlier

相关推荐
2501_9160088920 小时前
Xcode功能、下载、反馈与版本支持详细解析
ide·vscode·macos·ios·个人开发·xcode·敏捷流程
扬帆破浪1 天前
免费开源AI软件.桌面单机版,可移动的AI知识库,察元 AI桌面版:macOS首次启动报无法验证 开发者签名与公证的现实做法
人工智能·macos·开源·知识图谱
irpywp1 天前
合盖断网打断后台计算,Modafinil:一款防休眠菜单栏工具,让 Mac 闭眼继续跑 Agent
macos·ios·开源·github
一只AI打工虾的自我修养2 天前
DeepSeek V4.1 vs Ollama vs LocalClaw:Mac本地AI工具横评
人工智能·windows·macos
拂晓 AI 编程2 天前
Mac 本地跑 GUI Agent:4B 模型实现云端效果
macos
薛定猫AI2 天前
【深度解析】Gemma Chat:基于 MLX 的 Mac 离线 Coding Agent 架构与实战
macos·架构
夏沫琅琊2 天前
Mac 上用 Homebrew 安装 DB Browser for SQLite 时,被 Homebrew 自动更新卡住了
数据库·macos·sqlite
日月新著2 天前
仙踪问道·爱马仕助手深度评测:Mac 本地大模型零门槛部署实录
macos
布朗克1682 天前
Claude Code 2026中文教程指南入门:Mac/Windows安装配置全攻略
windows·macos·claude·code
2501_916007472 天前
XCode 15 IDE新特性:苹果集成开发环境全面升级,提升编程效率与体验
ide·vscode·macos·ios·个人开发·xcode·敏捷流程