【问题标题】:How to check if command line tools is installed如何检查是否安装了命令行工具
【发布时间】:2013-02-28 14:20:25
【问题描述】:

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

【问题讨论】:

  • XCode的版本是4.6

标签: xcode macos


【解决方案1】:

10.15 卡特琳娜更新:

查看优胜美地更新。

10.14 莫哈韦更新:

查看优胜美地更新。

10.13 High Sierra 更新:

查看优胜美地更新。

10.12 Sierra 更新:

查看优胜美地更新。

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 有一个命令行工具条目,它处于更新状态,当我更新它时,它显示状态为已安装
  • 不用进入/var/db/receipts目录,你可以使用它的API: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。这是什么意思?
【解决方案2】:

优胜美地

以下是一些人可能需要的新 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.

在提示显示许可协议时按 Enter。

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 中的路径。
【解决方案3】:

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

xcode-select --version

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

如果没有安装命令行工具运行:

xcode-select --install

【讨论】:

  • 简单有效。可能是最好的答案。
  • 节省了很多时间。谢谢老哥!
【解决方案4】:

在 macOS Sierra (10.12) 上:

  1. 运行以下命令查看是否安装了 CLT:

    xcode-select -p
    

    如果已安装 CLT,这将返回工具的路径。像这样的 -

    /Applications/Xcode.app/Contents/Developer
    
  2. 运行以下命令查看 CLT 的版本:

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

    这将返回版本信息,输出将是这样的 -

    package-id: com.apple.pkg.CLTools_Executables
    version: 8.2.0.0.1.1480973914
    volume: /
    location: /
    install-time: 1486372375
    

【讨论】:

    【解决方案5】:

    在 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

    【讨论】:

      【解决方案6】:

      我认为找到命令行工具的最简单方法是否已安装及其版本与 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:不适用
      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
      

      【讨论】:

      • 清晰简单的一个。非常感谢。
      【解决方案7】:

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

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

      【讨论】:

        【解决方案8】:

        从编程的角度来看,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

        【讨论】:

          【解决方案9】:

          在 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
          

          【讨论】:

            【解决方案10】:

            由于 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 使用非常短的命令来处理变化,但无法提供详细的包、版本和安装日期元数据。

            【讨论】:

              【解决方案11】:

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

              xcode-select -p
              

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

              /Library/Developer/CommandLineTools
              

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

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

              brew config
              

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

              祝你好运。

              【讨论】:

                【解决方案12】:

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

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

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

                【讨论】:

                  猜你喜欢
                  • 2014-02-11
                  • 2021-09-20
                  • 1970-01-01
                  • 2012-03-08
                  • 1970-01-01
                  • 1970-01-01
                  • 2010-11-05
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多