xcode 如何检查是否安装了命令行工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15371925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check if command line tools is installed
提问by Vivek Nandavanam
I have a macbook pro with OS X 10.8.2. XCode is installed. I know this as it appears in the Applications directory. There are also the xcodebuild and xcode-select files in /usr/bin I need to know if the command line tools is installed. Is there a command for it? What can I do to see if XCode CLT is installed and if yes to find the version installed?
我有一台装有 OS X 10.8.2 的 macbook pro。XCode 已安装。我知道这一点,因为它出现在 Applications 目录中。/usr/bin下还有xcodebuild和xcode-select文件我需要知道是否安装了命令行工具。有命令吗?我该怎么做才能查看是否安装了 XCode CLT,如果是,则可以找到安装的版本?
回答by jnovack
10.14 Mojave Update:
10.14 莫哈韦更新:
See Yosemite Update.
请参阅优胜美地更新。
10.13 High Sierra Update:
10.13 High Sierra 更新:
See Yosemite Update.
请参阅优胜美地更新。
10.12 Sierra Update:
10.12 塞拉更新:
See Yosemite Update.
请参阅优胜美地更新。
10.11 El Capitan Update:
10.11 El Capitan 更新:
See Yosemite Update.
请参阅优胜美地更新。
10.10 Yosemite Update:
10.10 优胜美地更新:
Just enter in gcc
or make
on the command line! OSX will know that you do not have the command line tools and prompt you to install them!
只需在命令行中输入gcc
或输入即可make
!OSX 会知道您没有命令行工具并提示您安装它们!
To check if they exist, xcode-select -p
will print the directory. Alternatively, the return value will be 2
if they do NOT exist, and 0
if they do. To just print the return value (thanks @Andy):
要检查它们是否存在,xcode-select -p
将打印目录。或者,返回值将是2
如果它们不存在,0
如果它们存在。只打印返回值(感谢@Andy):
xcode-select -p 1>/dev/null;echo $?
10.9 Mavericks Update:
10.9 小牛更新:
Use pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
用 pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
10.8 Update:
10.8 更新:
Option 1:Rob Napiersuggested to use pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
, which is probably cleaner.
选项 1:Rob Napier建议使用pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
,这可能更清洁。
Option 2:Check inside /var/db/receipts/com.apple.pkg.DeveloperToolsCLI.plist
for a reference to com.apple.pkg.DeveloperToolsCLI
and it will list the version 4.5.0
.
选项 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";
};
}
回答by phyatt
Yosemite
优胜美地
Below are a few extra steps on a fresh Mac that some people might need. This adds a little to @jnovack's excellent answer.
下面是一些人可能需要的新 Mac 上的一些额外步骤。这为@jnovack 的出色答案增添了一点。
Update: A few other notes when setting this up:
更新:设置时的其他一些注意事项:
Make sure your admin user has a password. A blank password won't work when trying to enable a root user.
确保您的管理员用户有密码。尝试启用 root 用户时,空白密码将不起作用。
System Preferences > Users and Groups > (select user) > Change password
Then to enable root, run dsenableroot
in a terminal:
然后要启用 root,请dsenableroot
在终端中运行:
$ dsenableroot
username = mac_admin_user
user password:
root password:
verify root password:
dsenableroot:: ***Successfully enabled root user.
Type in the admin user's password, then the new enabled root password twice.
输入 admin 用户的密码,然后输入两次新启用的 root 密码。
Next type:
下一个类型:
sudo gcc
or
或者
sudo make
It will respond with something like the following:
它将响应如下:
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.
Press enter when it prompts to show you the license agreement.
当它提示您显示许可协议时按 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:
//...
Press q
to exit the license agreement view.
按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]
Type agree
. And then it will end with:
键入agree
。然后它将以:
clang: error: no input files
Which basically means that you didn't give make
or gcc
any input files.
这基本上意味着您没有提供make
或gcc
任何输入文件。
Here is what the check looked like:
这是支票的样子:
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
Mavericks
小牛队
With Mavericks, it is a little different now.
对于小牛队,现在有点不同。
When the tools were NOT found, this is what the command pkgutil
command returned:
当未找到工具时,这是命令pkgutil
命令返回的内容:
$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
To install the command line tools, this works nicely from the Terminal, with a nice gui and everything.
要安装命令行工具,这可以从终端很好地工作,具有很好的 gui 和所有内容。
$ xcode-select --install
http://macops.ca/installing-command-line-tools-automatically-on-mavericks/
http://macops.ca/installing-command-line-tools-automatically-on-mavericks/
When they were found, this is what the pkgutil
command returned:
当它们被找到时,这是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
This command returned the same before and after the install.
此命令在安装前后返回相同。
$ pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
Also I had the component for the CLT selected and installed in xcode's downloads section before, but it seems like it didn't make it to the terminal...
此外,我之前在 xcode 的下载部分选择并安装了 CLT 的组件,但它似乎没有进入终端......
Hope that helps.
希望有帮助。
回答by user3476766
To check if command line tools are installed run:
要检查是否安装了命令行工具,请运行:
xcode-select --version
// if installed you will see the below with the version found in your system
// xcode-select version 1234.
If command line tools are not installed run:
如果未安装命令行工具,请运行:
xcode-select --install
回答by sahilabrar
On macOS Sierra (10.12) :
在 macOS Sierra (10.12) 上:
Run the following command to see if CLT is installed:
xcode-select -p
this will return the path to the tool if CLT is already installed. Something like this -
/Applications/Xcode.app/Contents/Developer
Run the following command to see the version of CLT:
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
this will return version info, output will be something like this -
package-id: com.apple.pkg.CLTools_Executables version: 8.2.0.0.1.1480973914 volume: / location: / install-time: 1486372375
运行以下命令查看是否安装了 CLT:
xcode-select -p
如果已经安装了 CLT,这将返回工具的路径。像这样的东西——
/Applications/Xcode.app/Contents/Developer
运行以下命令查看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
回答by Paul F. Wood
In macOS Catalina, and possibly some earlier versions, you can find out where the command line tools are installed using:
在 macOS Catalina以及可能的一些早期版本中,您可以使用以下命令找出命令行工具的安装位置:
xcode-select -p
a.k.a. xcode-select --print-path
xcode-select -p
又名 xcode-select --print-path
Which will, if it is installed, respond with something like:
如果已安装,它将响应如下:
/Library/Developer/CommandLineTools
/Library/Developer/CommandLineTools
To find out which version you have installed there, you can use:
要找出您在那里安装了哪个版本,您可以使用:
xcode-select -v
a.k.a. xcode-select --version
xcode-select -v
又名 xcode-select --version
Which will return something like:
这将返回如下内容:
xcode-select version 2370.
xcode-select version 2370.
However, if you attempt to upgrade it to the latest version, assuming it is installed, using this:
但是,如果您尝试将其升级到最新版本(假设已安装),请使用以下命令:
xcode-select --install
xcode-select --install
You will receive in response:
您将收到以下回复:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Which rather erroneously gives the impression you need to use Spotlight find something called 'Software Update'. In actual fact, you need to continue in the Terminal, and use this:
这相当错误地给人的印象是您需要使用 Spotlight 找到称为“软件更新”的东西。实际上,您需要在终端中继续,并使用它:
softwareupdate -i -a
a.k.a. softwareupdate --install --all
softwareupdate -i -a
又名 softwareupdate --install --all
Which tries to update everything it can and may well respond with:
它试图更新它可以更新的所有内容,并且很可能会响应:
Software Update Tool
Finding available software
No new software available.
To find out which versions of the different Apple SDKs are installed on your machine, use this:
要了解您的机器上安装了哪些版本的不同 Apple SDK,请使用以下命令:
xcodebuild -showsdks
xcodebuild -showsdks
回答by Jagdish Adusumalli
I think the simplest way which worked for me to find Command line tools is installed or not and its version irrespective of what macOS version is
我认为最简单的方法是让我找到命令行工具是否已安装及其版本,而不管 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:10.1.0.0.1.1539992718
Xcode:10.1
This when you have Command Line tools properly installed and paths set properly.
当您正确安装了命令行工具并正确设置了路径时。
Earlier i got output as below
macOS: 10.14.2-x86_64
CLT: N/A
Xcode: 10.1
早些时候我得到如下输出
macOS: 10.14.2-x86_64
CLT: N/A
Xcode: 10.1
CLT was shown as N/A in spite of having gcc and make working fine and below outputs
尽管有 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.
Finally doing xcode-select --install resolved my issue of brew unable to find CLT for installing packages as below.
最后执行 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
回答by Anon
From a programmatic perspective the Homebrew folks have a check for the existence of various files to determine if the command line tools are installed. Currently it always checks for /Library/Developer/CommandLineTools/usr/bin/git
and will also check for /usr/include/iconv.h
if the OS version is 10.13 or below.
从编程的角度来看,Homebrew 人员会检查各种文件是否存在,以确定是否安装了命令行工具。目前它总是检查 /Library/Developer/CommandLineTools/usr/bin/git
并且还会检查/usr/include/iconv.h
操作系统版本是否为 10.13 或更低。
回答by Bruno
Go to Applications > Xcode > preferences > downloads
转到应用程序 > Xcode > 首选项 > 下载
You should see the command line tools there for you to install.
您应该在那里看到命令行工具供您安装。
回答by P i
A lucid explanation can be found here: https://derflounder.wordpress.com/2013/11/15/xcode-command-line-tools-included-with-xcode-5-0-x-on-mavericks/
一个清晰的解释可以在这里找到:https: //derflounder.wordpress.com/2013/11/15/xcode-command-line-tools-included-with-xcode-5-0-x-on-mavericks/
I didn't find any of the existing answers here helpful.
我在这里没有发现任何现有的答案有帮助。
回答by BaseZen
Because Xcode subsumes the CLI tools if installed first, I use the following hybrid which has been validated on 10.12 and 10.14. I expect it works on a lot of other versions:
因为如果首先安装 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)
installed=$(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables 2>/dev/null || pkgutil --pkg-info=com.apple.pkg.Xcode)
Salt with awk
to taste for branching logic.
用盐awk
来品尝分支逻辑。
Of course xcode-select -p
handles the variations with a really short command but fails to give the detailed package, version, and installation date metadata.
当然xcode-select -p
用一个非常短的命令来处理这些变化,但没有给出详细的包、版本和安装日期元数据。