ChatGPT解决这个技术问题 Extra ChatGPT

如何检查是否安装了命令行工具

我有一台装有 OS X 10.8.2 的 macbook pro。 XCode 已安装。我知道这一点,因为它出现在 Applications 目录中。 /usr/bin 中还有 xcodebuild 和 xcode-select 文件我需要知道是否安装了命令行工具。有命令吗?我可以做些什么来查看是否安装了 XCode CLT,如果是的话来查找安装的版本?

XCode 的版本是 4.6

I
Ian

10.15 卡特琳娜更新:

请参阅优胜美地更新。

10.14 莫哈韦更新:

请参阅优胜美地更新。

10.13 高山脉更新:

请参阅优胜美地更新。

10.12 塞拉利昂更新:

请参阅优胜美地更新。

10.11 埃尔卡皮坦更新:

请参阅优胜美地更新。

10.10 优胜美地更新:

只需在命令行输入 gccmake! OSX 会知道您没有命令行工具并提示您安装它们!

为了检查它们是否存在,xcode-select -p 将打印目录。或者,如果它们不存在,则返回值为 2,如果存在,则返回值为 0。只打印返回值(感谢@Andy):

xcode-select -p 1>/dev/null;echo $?

10.9 小牛队更新:

使用pkgutil --pkg-info=com.apple.pkg.CLTools_Executables

10.8 更新:

选项 1: Rob Napier 建议使用 pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI,这可能更简洁。

选项 2:/var/db/receipts/com.apple.pkg.DeveloperToolsCLI.plist 中检查对 com.apple.pkg.DeveloperToolsCLI 的引用,它将列出版本 4.5.0

[Mar 12 17:04] [jnovack@yourmom ~]$ defaults read /var/db/receipts/com.apple.pkg.DeveloperToolsCLI.plist
{
    InstallDate = "2012-12-26 22:45:54 +0000";
    InstallPrefixPath = "/";
    InstallProcessName = Xcode;
    PackageFileName = "DeveloperToolsCLI.pkg";
    PackageGroups =     (
        "com.apple.FindSystemFiles.pkg-group",
        "com.apple.DevToolsBoth.pkg-group",
        "com.apple.DevToolsNonRelocatableShared.pkg-group"
    );
    PackageIdentifier = "com.apple.pkg.DeveloperToolsCLI";
    PackageVersion = "4.5.0.0.1.1249367152";
    PathACLs =     {
        Library = "!#acl 1\\ngroup:ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000000C:everyone:12:deny:delete\\n";
        System = "!#acl 1\\ngroup:ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000000C:everyone:12:deny:delete\\n";
    };
}

我发现打开 xcode>Preferences>Downloads>Components 有一个处于更新状态的命令行工具条目,当我更新它时,它显示状态为已安装
您可以使用 API,而不是进入 /var/db/receipts 目录:pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
我可能弄错了,但收据名称现在是 CLTools_Executables,至少这是我在 OS Mavericks 下找到的所有内容。该命令将是:pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
注意到和乔丹一样的事情。 xcode-select 不返回int,只返回路径
我输入了xcode-select-p,才得到/Applications/Xcode.app/Contents/Developer。这是什么意思?
p
phyatt

优胜美地

以下是一些人可能需要的新 Mac 上的一些额外步骤。这为@jnovack 的出色回答增加了一点点。

更新:设置时的其他一些注意事项:

确保您的管理员用户有密码。尝试启用 root 用户时,空白密码将不起作用。

System Preferences > Users and Groups > (select user) > Change password

然后要启用 root,请在终端中运行 dsenableroot

$ dsenableroot
username = mac_admin_user
user password:
root password:
verify root password:

dsenableroot:: ***Successfully enabled root user.

输入管理员用户的密码,然后输入新启用的 root 密码两次。

下一个类型:

sudo gcc

或者

sudo make

它会响应如下内容:

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:


You have not agreed to the Xcode license agreements. You must agree to 
both license agreements below in order to use Xcode.

当它提示您显示许可协议时按回车键。

Hit the Enter key to view the license agreements at 
'/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'

IMPORTANT: BY USING THIS SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE 
FOLLOWING APPLE TERMS:

//...

q 退出许可协议视图。

By typing 'agree' you are agreeing to the terms of the software license 
agreements. Type 'print' to print them or anything else to cancel, 
[agree, print, cancel]

键入 agree。然后它将以:

clang: error: no input files 

这基本上意味着您没有提供 makegcc 任何输入文件。

这是支票的样子:

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

小牛队

有了小牛队,现在有点不同了。

未找到工具时,命令 pkgutil 命令返回以下内容:

$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

要安装命令行工具,这可以在终端上很好地工作,带有漂亮的 gui 和一切。

$ xcode-select --install

http://macops.ca/installing-command-line-tools-automatically-on-mavericks/

找到它们后,pkgutil 命令返回以下内容:

$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 5.0.1.0.1.1382131676
volume: /
location: /
install-time: 1384149984
groups: com.apple.FindSystemFiles.pkg-group com.apple.DevToolsBoth.pkg-group com.apple.DevToolsNonRelocatableShared.pkg-group 

此命令在安装前后返回相同的结果。

$ pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

此外,我之前在 xcode 的下载部分中选择并安装了 CLT 的组件,但它似乎没有进入终端......

希望有帮助。


您可以为最新的操作系统更新此答案吗?谢谢。
我调用了 sudo rm -rf /Library/Developer/CommandLineTools,然后调用了 xcode-select --install。
@study 您在运行 xcode-select-p 时获得了 /Applications/Xcode.app/Contents/Developer,因为这就是 Mac Sierra 中的路径。
u
user3476766

要检查是否安装了命令行工具,请运行:

xcode-select --version

// if installed you will see the below with the version found in your system
// xcode-select version 1234.

如果未安装命令行工具,请运行:

xcode-select --install

简单有效。可能是最好的答案。
节省了很多时间。谢了哥们!
P
Paul F. Wood

在 macOS Catalina 以及可能的一些早期版本中,您可以使用以下命令查找命令行工具的安装位置:

xcode-select -p又名xcode-select --print-path

如果已安装,它将响应以下内容:

/Library/Developer/CommandLineTools

要找出您在那里安装的版本,您可以使用:

xcode-select -v又名xcode-select --version

这将返回如下内容:

xcode-select version 2370.

但是,如果您尝试将其升级到最新版本,假设已安装,请使用以下命令:

xcode-select --install

您将收到以下回复:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

这相当错误地给人的印象是你需要使用 Spotlight 找到一个叫做“软件更新”的东西。实际上,您需要在终端中继续,并使用以下命令:

softwareupdate -i -a又名softwareupdate --install --all

它试图更新它可以更新的所有内容,并且很可能会回应:

Software Update Tool

Finding available software
No new software available.

要找出您的机器上安装了哪些不同 Apple SDK 的版本,请使用以下命令:

xcodebuild -showsdks


s
sahilabrar

在 macOS Sierra (10.12) 上:

运行以下命令以查看是否安装了 CLT: xcode-select -p 如果已安装 CLT,这将返回工具的路径。像这样 - /Applications/Xcode.app/Contents/Developer 运行以下命令以查看 CLT 的版本: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables 这将返回版本信息,输出将类似于这 - 包 ID:com.apple.pkg.CLTools_Executables 版本:8.2.0.0.1.1480973914 卷:/位置:/安装时间:1486372375


J
Jagdish Adusumalli

我认为对我来说找到命令行工具的最简单方法是否已安装及其版本与 macOS 版本无关

$brew config

macOS:10.14.2-x86_64 CLT:10.1.0.0.1.1539992718 Xcode:10.1

当您正确安装了命令行工具并正确设置了路径时。

早些时候我得到如下输出 macOS: 10.14.2-x86_64 CLT: N/A Xcode: 10.1

尽管有 gcc 并且使工作正常且低于输出,但 CLT 显示为 N/A

$xcode-select -p              
/Applications/Xcode.app/Contents/Developer
$pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
$brew doctor
Your system is ready to brew.

最后做 xcode-select --install 解决了我的 brew 无法找到 CLT 来安装包的问题,如下所示。

Installing sphinx-doc dependency: python
Warning: Building python from source:
  The bottle needs the Apple Command Line Tools to be installed.
  You can install them, if desired, with:
    xcode-select --install

清晰而简单的一种。非常感激。
B
Bruno

转到应用程序 > Xcode > 首选项 > 下载

您应该在那里看到命令行工具供您安装。


A
Anon

从程序化的角度来看,Homebrew folks have a check for the existence of various files to determine if the command line tools are installed。目前,它始终检查 /Library/Developer/CommandLineTools/usr/bin/git,如果操作系统版本为 10.13 或更低,还将检查 /usr/include/iconv.h


G
Gonçalo

在 bash 脚本上使用:

if ! command -v xcode-select &> /dev/null
then
    echo "\t xcode was not found! You need to manually install it :/ "
else
    echo "xcode is installed, checking other IOS build tools"
fi

B
BaseZen

因为如果首先安装 Xcode 包含 CLI 工具,我使用以下已在 10.12 和 10.14 上验证的混合。我希望它适用于许多其他版本:

installed=$(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables 2>/dev/null || pkgutil --pkg-info=com.apple.pkg.Xcode)

awk 加盐来品尝分支逻辑。

当然,xcode-select -p 使用非常短的命令处理变体,但未能提供详细的包、版本和安装日期元数据。


Z
ZaMy

打开你的终端并检查你是否已经安装了 Xcode:

xcode-select -p

作为回报,如果你得到这个:

/Library/Developer/CommandLineTools

这意味着您已经安装了 Xcode。

另一种方法是检查是否安装了“HomeBrew”,您可以使用以下命令查看是否安装了 Xcode 和版本:

brew config

最后,如果您没有 Xcode,请点击此链接从 Appstore 下载 Xcode。 Xcode from the App Store

祝你好运。


O
Old Sub Sailor

% xcode-select -h 用法:xcode-select [选项]

打印或更改活动开发者目录的路径。该目录控制用于 Xcode 命令行工具(例如 xcodebuild)以及 BSD 开发命令(例如 cc 和 make)的工具。

选项: -h, --help 打印此帮助信息并退出 -p, --print-path 打印活动开发者目录的路径 -s , --switch 设置活动开发者目录的路径 --install 打开一个对话框用于安装命令行开发者工具 -v,--version 打印 xcode-select 版本 -r,--reset 重置为默认命令行工具路径