获取精确的 macOS 版本号与 Build 号
sw_vers 与 uname 一行命令给出准确的系统版本、Build 号和内核架构。
运行 `sw_vers` 查看产品版本和 Build 号,用 `uname -m` 查看 CPU 架构(arm64 还是 x86_64)。
01命令
命令
$ sw_vers -productVersion && sw_vers -buildVersion && uname -m02作用说明
"关于本机"显示的是 15.2 这类市场版本号,而技术支持和兼容性表格需要的是 Build 号,sw_vers -buildVersion 正是为此准备的。当 sw_vers 不可用时,可用 `sysctl -n kern.osproductversion` 和 `sysctl -n machdep.cpu.brand_string` 获取内核层面的信息。在部署脚本中做系统判断,这几个命令是最快的组合。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- macOS sw_vers — display the macOS version and build依据: Documents sw_vers -productVersion, -buildVersion and -osVersion flags.
最后验证: 2026-09-17 · 分类: 系统与设置