当前位置: 首页 > news >正文

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/Home1.8.0_261 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home1.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.81.8.0.261oracle64-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/Home1.8.261.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home1.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 versionssystem1.81.8.0.2612121.021.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 versionssystem1.81.8.0.2612121.021.0.8oracle64-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

http://www.dtcms.com/a/340309.html

相关文章:

  • 基于YOLO11的手机违规使用检测模型训练实战
  • MySQL诊断系列(3/6):索引分析——5个SQL揪出“僵尸索引”
  • Docker Compose命令一览(Docker Compose指令、docker-compose命令)
  • 动态规划----8.乘积最大子数组
  • 遥感机器学习入门实战教程|Sklearn 案例④ :多分类器对比(SVM / RF / kNN / Logistic...)
  • 详解 scikit-learn 数据预处理工具:从理论到实践
  • 5.4 4pnpm 使用介绍
  • 给你的Unity编辑器添加实现类似 Odin 的 条件显示字段 (ShowIf/HideIf) 功能
  • Scikit-learn 预处理函数分类详解
  • pnpm : 无法加载文件 C:\Program Files\nodejs\pnpm.ps1,因为在此系统上禁止运行脚本。
  • 在 React 中,​父子组件之间的通信(传参和传方法)
  • scikit-learn/sklearn学习|变量去中心化和标准化
  • 2.3 Flink的核心概念解析
  • 详解flink java table api基础(三)
  • Flink Stream API - 顶层Operator接口StreamOperator源码超详细讲解
  • OSPF 典型组网
  • CISP-PTE之路--10文
  • 公有地址和私有地址
  • 【GPT入门】第51课 将hf模型转换为GGUF
  • 深入(流批【牛批】框架)Flink的机制
  • 【Java后端】Spring Boot 全局异常处理最佳实践
  • ssl代理
  • 一会儿能ping通一会ping不通解决方案
  • JavaScript手录18-ajax:异步请求与项目上线部署
  • AI 自动化编程 trae 体验 页面添加富编辑器
  • (5)软件包管理器 yum | Vim 编辑器 | Vim 文本批量化操作 | 配置 Vim
  • 深度解析:RESTful API中的404错误 - 不是所有404都是Bug
  • Vue 3项目中的路由管理和状态管理系统
  • 【Day 31】Linux-LNMP
  • MySQL基础操作