mac mini 安装java JDK 17

这里写自定义目录标题

  • [使用homebrew 进行安装](#使用homebrew 进行安装)
  • [配置java 环境](#配置java 环境)
  • [使用jenv 来管理java 版本](#使用jenv 来管理java 版本)

使用homebrew 进行安装

检查系统版本

复制代码
uname -m
# 输出 arm64

安装jdk 17

复制代码
brew install openjdk@17

安装过程

复制代码
==> 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
agent-browser: Browser automation CLI for AI agents
cozyhr: Cozy wrapper around Helm and Flux CD for local development
ic-wasm: CLI tool for performing Wasm transformations specific to ICP canisters
icp-cli: Development tool for building and deploying canisters on ICP
jqfmt: Opinionated formatter for jq
static-web-apps-cli: SWA CLI serves as a local development tool for Azure Static Web Apps
yap: On-device audio transcription using Speech.framework
==> New Casks
clash-mi: Another Mihomo GUI based on Flutter
codex-app: OpenAI's Codex desktop app for managing coding agents
codexbar: Menu bar usage monitor for Codex and Claude
luxury-yacht: Desktop app for managing Kubernetes clusters
plasticity: 3D modeling software for concept artists and designers
posturr: Posture monitoring app
repobar: Menu bar dashboard for GitHub repository health
tana: Knowledge management workspace with AI-powered outlining
thaw: Menu bar manager
trimmy: Paste-once, run-once clipboard cleaner for terminal snippets
yandextelemost: Yandex video calls and meetings platform

You have 1 outdated formula installed.

==> Fetching downloads for: openjdk@17
✔︎ Bottle libpng (1.6.54)                             Downloaded  459.0KB/459.0KB
✔︎ Bottle freetype (2.14.1_1)                         Downloaded  991.0KB/991.0KB
✔︎ Bottle giflib (5.2.2)                              Downloaded  153.0KB/153.0KB
✔︎ Bottle fontconfig (2.17.1)                         Downloaded  400.1KB/400.1KB
✔︎ Bottle pcre2 (10.47_1)                             Downloaded    2.4MB/  2.4MB
✔︎ Bottle glib (2.86.3)                               Downloaded    9.2MB/  9.2MB
✔︎ Bottle xorgproto (2025.1)                          Downloaded  720.1KB/720.1KB
✔︎ Bottle libxau (1.0.12)                             Downloaded   33.4KB/ 33.4KB
✔︎ Bottle libxdmcp (1.1.5)                            Downloaded   36.8KB/ 36.8KB
✔︎ Bottle libxcb (1.17.0)                             Downloaded  999.8KB/999.8KB
✔︎ Bottle libx11 (1.8.12)                             Downloaded    2.3MB/  2.3MB
✔︎ Bottle libxext (1.3.7)                             Downloaded  109.6KB/109.6KB
✔︎ Bottle libxrender (0.9.12)                         Downloaded   54.6KB/ 54.6KB
✔︎ Bottle lzo (2.10)                                  Downloaded  149.6KB/149.6KB
✔︎ Bottle pixman (0.46.4)                             Downloaded  416.2KB/416.2KB
✔︎ Bottle cairo (1.18.4)                              Downloaded    1.6MB/  1.6MB
✔︎ Bottle graphite2 (1.3.14)                          Downloaded   92.6KB/ 92.6KB
✔︎ Bottle icu4c@78 (78.2)                             Downloaded   31.8MB/ 31.8MB
✔︎ Bottle harfbuzz (12.3.2)                           Downloaded    3.1MB/  3.1MB
✔︎ Bottle jpeg-turbo (3.1.3)                          Downloaded    1.1MB/  1.1MB
✔︎ Bottle xz (5.8.2)                                  Downloaded  764.3KB/764.3KB
✔︎ Bottle lz4 (1.10.0)                                Downloaded  279.7KB/279.7KB
✔︎ Bottle zstd (1.5.7_1)                              Downloaded  793.6KB/793.6KB
✔︎ Bottle libtiff (4.7.1_1)                           Downloaded    1.9MB/  1.9MB
✔︎ Bottle little-cms2 (2.18)                          Downloaded  434.8KB/434.8KB
✔︎ Bottle openjdk@17 (17.0.18)                        Downloaded  186.2MB/186.2MB
==> Installing dependencies for openjdk@17: libpng, freetype, giflib, fontconfig, pcre2, glib, xorgproto, libxau, libxdmcp, libxcb, libx11, libxext, libxrender, lzo, pixman, cairo, graphite2, icu4c@78, harfbuzz, jpeg-turbo, xz, lz4, zstd, libtiff and little-cms2
==> Installing openjdk@17 dependency: libpng
==> Pouring libpng-1.6.54.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libpng/1.6.54: 28 files, 1.4MB
==> Installing openjdk@17 dependency: freetype
==> Pouring freetype-2.14.1_1.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/freetype/2.14.1_1: 68 files, 2.7MB
==> Installing openjdk@17 dependency: giflib
==> Pouring giflib-5.2.2.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/giflib/5.2.2: 20 files, 559.4KB
==> Installing openjdk@17 dependency: fontconfig
==> Pouring fontconfig-2.17.1.arm64_tahoe.bottle.1.tar.gz
==> Regenerating font cache, this may take a while
==> /opt/homebrew/Cellar/fontconfig/2.17.1/bin/fc-cache --force --really-force -
🍺  /opt/homebrew/Cellar/fontconfig/2.17.1: 98 files, 1.6MB
==> Installing openjdk@17 dependency: pcre2
==> Pouring pcre2-10.47_1.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/pcre2/10.47_1: 244 files, 7.3MB
==> Installing openjdk@17 dependency: glib
==> Pouring glib-2.86.3.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/glib/2.86.3: 504 files, 39.6MB
==> Installing openjdk@17 dependency: xorgproto
==> Pouring xorgproto-2025.1.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/xorgproto/2025.1: 268 files, 4.1MB
==> Installing openjdk@17 dependency: libxau
==> Pouring libxau-1.0.12.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libxau/1.0.12: 21 files, 137.3KB
==> Installing openjdk@17 dependency: libxdmcp
==> Pouring libxdmcp-1.1.5.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libxdmcp/1.1.5: 12 files, 142.9KB
==> Installing openjdk@17 dependency: libxcb
==> Pouring libxcb-1.17.0.arm64_tahoe.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/libxcb/1.17.0: 2,498 files, 7.9MB
==> Installing openjdk@17 dependency: libx11
==> Pouring libx11-1.8.12.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libx11/1.8.12: 1,043 files, 7.4MB
==> Installing openjdk@17 dependency: libxext
==> Pouring libxext-1.3.7.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libxext/1.3.7: 88 files, 472.4KB
==> Installing openjdk@17 dependency: libxrender
==> Pouring libxrender-0.9.12.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libxrender/0.9.12: 13 files, 230.3KB
==> Installing openjdk@17 dependency: lzo
==> Pouring lzo-2.10.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/lzo/2.10: 32 files, 579.7KB
==> Installing openjdk@17 dependency: pixman
==> Pouring pixman-0.46.4.arm64_tahoe.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/pixman/0.46.4: 11 files, 1.4MB
==> Installing openjdk@17 dependency: cairo
==> Pouring cairo-1.18.4.arm64_tahoe.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/cairo/1.18.4: 58 files, 4.7MB
==> Installing openjdk@17 dependency: graphite2
==> Pouring graphite2-1.3.14.arm64_tahoe.bottle.2.tar.gz
🍺  /opt/homebrew/Cellar/graphite2/1.3.14: 19 files, 277.4KB
==> Installing openjdk@17 dependency: icu4c@78
==> Pouring icu4c@78-78.2.arm64_tahoe.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/icu4c@78/78.2: 279 files, 87.7MB
==> Installing openjdk@17 dependency: harfbuzz
==> Pouring harfbuzz-12.3.2.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/harfbuzz/12.3.2: 77 files, 11.6MB
==> Installing openjdk@17 dependency: jpeg-turbo
==> Pouring jpeg-turbo-3.1.3.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/jpeg-turbo/3.1.3: 47 files, 3.7MB
==> Installing openjdk@17 dependency: xz
==> Pouring xz-5.8.2.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/xz/5.8.2: 96 files, 2.7MB
==> Installing openjdk@17 dependency: lz4
==> Pouring lz4-1.10.0.arm64_tahoe.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/lz4/1.10.0: 24 files, 768.8KB
==> Installing openjdk@17 dependency: zstd
==> Pouring zstd-1.5.7_1.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/zstd/1.5.7_1: 32 files, 2.3MB
==> Installing openjdk@17 dependency: libtiff
==> Pouring libtiff-4.7.1_1.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libtiff/4.7.1_1: 488 files, 9.0MB
==> Installing openjdk@17 dependency: little-cms2
==> Pouring little-cms2-2.18.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/little-cms2/2.18: 23 files, 1.5MB
==> Installing openjdk@17
==> Pouring openjdk@17-17.0.18.arm64_tahoe.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

openjdk@17 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have openjdk@17 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk@17 you may need to set:
  export CPPFLAGS="-I/opt/homebrew/opt/openjdk@17/include"
==> Summary
🍺  /opt/homebrew/Cellar/openjdk@17/17.0.18: 636 files, 319.9MB
==> Running `brew cleanup openjdk@17`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
==> Caveats
==> openjdk@17
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

openjdk@17 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have openjdk@17 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk@17 you may need to set:
  export CPPFLAGS="-I/opt/homebrew/opt/openjdk@17/include"

配置java 环境

复制代码
open -e ~/.zshrc

打开配置环境文件

复制代码
# JDK 17 环境变量配置
 export JAVA_HOME=$(brew --prefix openjdk@17)/libexec/openjdk.jdk/Contents/Home
 export PATH=$JAVA_HOME/bin:$PATH

执行

复制代码
source ~/.zshrc

验证1

复制代码
java -version
openjdk version "17.0.18" 2026-01-20
OpenJDK Runtime Environment Homebrew (build 17.0.18+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.18+0, mixed mode, sharing)

验证2

复制代码
javac -version
javac 17.0.18

使用jenv 来管理java 版本

复制代码
% brew install jenv
==> Fetching downloads for: jenv
✔︎ Bottle jenv (0.6.0)                                Downloaded   30.3KB/ 30.3KB
==> Pouring jenv-0.6.0.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
🍺  /opt/homebrew/Cellar/jenv/0.6.0: 92 files, 107.6KB
==> 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`).

查看版本

复制代码
jenv --version
jenv 0.6.0

配置jenv

将jdk 17 环境变量注释,使用jenv 来管理java jdk 版本

输入

复制代码
open -e ~/.zshrc

修改配置文件

复制代码
# JDK 17 环境变量配置
# export JAVA_HOME=$(brew --prefix openjdk@17)/libexec/openjdk.jdk/Contents/Home
# export PATH=$JAVA_HOME/bin:$PATH
# 配置java jdk 环境切换
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

配置生效

复制代码
source ~/.zshrc

查找javac 安装路径

复制代码
where javac
/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home/bin/javac
/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home/bin/javac
/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home/bin/javac
/usr/bin/javac

切换java 版本

复制代码
env versions
* system (set by /Users/jiaxinying/.jenv/version)
  17
  17.0
  17.0.18
  openjdk64-17.0.18
jiaxinying@Mac ~ % jenv global 17
jiaxinying@Mac ~ % jenv version
17 (set by /Users/jiaxinying/.jenv/version)
jiaxinying@Mac ~ % java -version
openjdk version "17.0.18" 2026-01-20
OpenJDK Runtime Environment Homebrew (build 17.0.18+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.18+0, mixed mode, sharing)
jiaxinying@Mac ~ % javac -version
javac 17.0.18
jiaxinying@Mac ~ % sudo ln -s /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
Password:
jiaxinying@Mac ~ % /usr/libexec/java_home -v 17
/opt/homebrew/Cellar/openjdk@17/17.0.18/libexec/openjdk.jdk/Contents/Home
jiaxinying@Mac ~ %
相关推荐
独望漫天星辰3 小时前
C++ 树结构进阶:从工程化实现到 STL 底层与性能优化
开发语言·c++
biyezuopinvip3 小时前
基于Spring Boot的企业网盘的设计与实现(毕业论文)
java·spring boot·vue·毕业设计·论文·毕业论文·企业网盘的设计与实现
HellowAmy3 小时前
我的C++规范 - 鸡蛋工厂
开发语言·c++·代码规范
Hx_Ma163 小时前
SSM搭建(三)Spring整合SpringMVC框架
java·后端·spring
叫我一声阿雷吧3 小时前
深入理解JavaScript作用域和闭包,解决变量访问问题
开发语言·javascript·ecmascript
无风听海3 小时前
.NET10之ASP.NET Core的Filter管线
java·asp.net·.net
froginwe113 小时前
Vue.js 事件处理器
开发语言
少许极端3 小时前
算法奇妙屋(二十八)-递归、回溯与剪枝的综合问题 1
java·算法·深度优先·剪枝·回溯·递归