Generally, after Xcode is installed, when it is opened for the first time, a pop-up window will prompt to install Command Line Tools, just install it directly.
If it is not installed at that time, it can also be installed separately later.
# 安装命令
xcode-select --install
# 查看版本
xcode-select --version
Sometimes there is a problem with Command Line Tools, you can first try to restore the default settings to solve it:
# 恢复默认设置(需要sudo权限)
sudo xcode-select --reset
Still can't solve it, you can consider deleting and reinstalling:
# 强制删除安装目录下的文件
sudo rm -rf /Library/Developer/CommandLineTools
# 重新安装
xcode-select --install
In addition to the installation method of terminal commands, you can also search for Command Line Tools in the download section of Apple's official website and download the installation package.