macos monterey(12.x)上安装Command Line Tools

macOS 中,Command Line Tools (CLT) 是 Apple 提供的一组开发工具包,用于在不安装完整 Xcode 的情况下运行命令行开发工具,如:
gccmakegitsvnlldbclangswiftc 等。


env

  • macbook pro 2019
  • command line tools(14.0.x)

1.Command Line Tools 主要用途

功能 说明
C/C++/Objective-C 开发 提供 clangmakeld 等基础编译工具
Git 支持 提供 git 命令(默认不带 GUI)
Python/Go/Rust 等语言构建 用于编译依赖的 C 库
Homebrew 依赖 Homebrew 必须依赖 CLT 或 Xcode
开发环境 可在没有完整 Xcode 的轻量环境中使用(如服务器或容器)

2.查看是否安装

1
xcode-select -p
  • 如果输出类似:

    /Library/Developer/CommandLineTools
    

    ✅ 表示已安装。

  • 如果提示:

    xcode-select: error: unable to get active developer directory...
    

    ❌ 表示未安装。


3.查看 CLT 版本号

1
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables

示例输出:

gaga@GaGa ~ % pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 14.0.0.0.1.1661618636
volume: /
location: /
install-time: 1758928293
groups: com.apple.FindSystemFiles.pkg-group 

如果你有完整 Xcode,也可以:

1
xcodebuild -version
命令 功能
clang --version 查看编译器版本
gcc --version 同上(实际上是 clang 的别名)
git --version 查看 git 版本
make 检查编译器工作是否正常

4.Command Line Tools 安装

Command Line Tools for Xcode 14