用 xcrun --find 定位开发者工具路径

xcrun 是苹果开发者工具的分发器,--find 可以打印任意工具的真实路径——该路径会随当前选中的 Xcode 或命令行工具而变化。

macOSxcrun 开发者工具命令行工具路径低风险
运行 `xcrun --find clang` 打印当前工具链中 clang 的绝对路径,或直接用 `xcrun clang` 调用。

01命令

命令
$ xcrun --find clang
xcrun --find swift
xcrun --find simctl

02作用说明

swift、simctl 等工具并不总在 PATH 中,而且当你用 xcode-select 切换工具链时位置会变,写死路径的脚本因此失效。`xcrun --find` 会根据当前 SDK 和开发者目录解析并输出二进制文件位置,而通过 `xcrun <tool>` 调用则能保证工具与所选工具链一致。

03风险

风险低风险
使用条件Command Line Tools or Xcode must be installed
!注意: 如果没有选中命令行工具或 Xcode,xcrun 会报许可或 "unable to find utility" 错误;用 xcode-select 修复。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

最后验证: 2026-09-17 · 分类: 开发者