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

时间:2013-03-12 20:54:02

标签: xcode macos

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

12 个答案:

答案 0 :(得分:79)

10.14 Mojave更新:

参见Yosemite Update。

10.13 High Sierra更新:

参见Yosemite Update。

10.12 Sierra Update:

参见Yosemite Update。

10.11 El Capitan更新:

参见Yosemite Update。

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";
    };
}

答案 1 :(得分:77)

优胜美

以下是有些人可能需要的新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的组件,但似乎它没有进入终端......

希望有所帮助。

答案 2 :(得分:18)

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

xcode-select --version

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

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

xcode-select --install

答案 3 :(得分:10)

在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
    

答案 4 :(得分:3)

在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.

答案 5 :(得分:1)

转到应用程序> Xcode>偏好>下载

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

答案 6 :(得分:1)

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

答案 7 :(得分:0)

清晰的解释可以在这里找到:https://derflounder.wordpress.com/2013/11/15/xcode-command-line-tools-included-with-xcode-5-0-x-on-mavericks/

我在这里找不到任何现有的答案。

答案 8 :(得分:0)

因为如果先安装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用一个很短的命令处理这些变化,但是没有提供详细的软件包,版本和安装日期元数据。

答案 9 :(得分:0)

我认为无论是否安装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

答案 10 :(得分:0)

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

xcode-select -p

如果得到的话,作为回报:

/Library/Developer/CommandLineTools

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

另一种检查方式是否为“ HomeBrew”,可以使用以下命令查看是否具有Xcode及其版本:

brew config

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

祝你好运。

答案 11 :(得分:0)

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

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

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