mac重新安装CommandLineTools(CLT)

Command Line Tools (CLT)是一组软件包,为 macOS 上的终端用户提供了许多常用的工具、实用程序和编译器。

简单来说,它就是一个小型独立的软件包,包含了许多在 Linux 默认安装中也能找到的实用命令,例如 svn、git、make、GCC、clang、perl、size、strip、strings、libtool、cpp、what 等等

env

  • macos-15.2(Sequoia)

1.查看存储路径

mvpbang:~ root# xcode-select -p
/Library/Developer/CommandLineTools

2.删除存储路径及记录脚本

2.1删除存储路径

sudo rm -rf /Library/Developer/CommandLineTools

2.2删除安装收据

  • /Library/Apple/System/Library/Receipts
    • com.apple.pkg.CLTools_Executables.{bom,plist}
    • com.apple.pkg.CLTools_SDK_macOS*.{bom,plist}
    • com.apple.pkg.CLTools_macOS_SDK.{bom,plist}
sudo su -

cd /Library/Apple/System/Library/Receipts
rm -rf com.apple.pkg.CLTools_Executables.{bom,plist}
rm -rf com.apple.pkg.CLTools_SDK_macOS*.{bom,plist}
rm -rf com.apple.pkg.CLTools_macOS_SDK.{bom,plist}

注意:需要关闭sip(系统保护)

3.重新安装CommandLineTools

3.1 reinstall latest

➜  ~ xcode-select --install   
xcode-select: note: install requested for command line developer tools

注意:会弹出gui点击安装

de186a864bae5477f46981e557777f5c.png

3.2安装完毕,再次安装会提示已安装

➜  ~ xcode-select --install
xcode-select: note: Command line tools are already installed. Use "Software Update" in System Settings or the softwareupdate command line interface to install updates

3.3查看命令

➜  ~ xcode-select -p
/Library/Developer/CommandLineTools

➜  ~ clang -v
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: x86_64-apple-darwin24.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

4.基于离线dmga安装

注意:需要登录apple账户,继续下载

e07f46fed03599e4364679cae36bd51f.png

5.xcode-select

➜  ~ xcode-select -h 
Usage: xcode-select [options]

Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example, 
xcodebuild) as well as the BSD development commands (such as cc and make).

Options:
  -h, --help                  print this help message and exit
  -p, --print-path            print the path of the active developer directory  # 打印路径
  -s <path>, --switch <path>  set the path for the active developer directory  # 切换开发目录
  --install                   open a dialog for installation of the command line developer tools   # 打开一个窗口,安装CLT(当前系统最新版本)
  -v, --version               print the xcode-select version
  -r, --reset                 reset to the default command line tools path  # 重置CLT路径

Refer