用 xcrun --find 定位开发者工具路径
xcrun 是苹果开发者工具的分发器,--find 可以打印任意工具的真实路径——该路径会随当前选中的 Xcode 或命令行工具而变化。
运行 `xcrun --find clang` 打印当前工具链中 clang 的绝对路径,或直接用 `xcrun clang` 调用。
01命令
命令
$ xcrun --find clang
xcrun --find swift
xcrun --find simctl02作用说明
swift、simctl 等工具并不总在 PATH 中,而且当你用 xcode-select 切换工具链时位置会变,写死路径的脚本因此失效。`xcrun --find` 会根据当前 SDK 和开发者目录解析并输出二进制文件位置,而通过 `xcrun <tool>` 调用则能保证工具与所选工具链一致。
03风险
!注意: 如果没有选中命令行工具或 Xcode,xcrun 会报许可或 "unable to find utility" 错误;用 xcode-select 修复。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- xcrun — run or locate developer tools (macOS)依据: Documents --find to print the path of the named developer tool.
- Installing the Command Line Tools依据: Apple documents the Command Line Tools that xcrun resolves against.
最后验证: 2026-09-17 · 分类: 开发者