简体   繁体   English

安装 Ruby 后 MAC OS X 上的活动开发者路径无效

[英]Invalid active developer path on MAC OS X after installing Ruby

I get this error:我收到此错误:

xcrun: error: invalid active developer path (/Applications/Xcode.app), missing xcrun at: /Applications/Xcode.app/usr/bin/xcrun

This solution works, but the error occurs again after closing my terminal and reopening it;解决方案有效,但关闭我的终端并重新打开后再次出现错误; I then have to run the same commands every time I open a new terminal window.然后,每次打开新的终端窗口时,我都必须运行相同的命令。

How can I apply these changes such that they will save after closing the terminal window out?如何应用这些更改,以便在关闭终端窗口后保存它们?

I started getting the same error after updating to OS X El Capitan.更新到 OS X El Capitan 后,我开始遇到同样的错误。
In my case, all I did was to install it:就我而言,我所做的就是安装它:

sudo xcode-select --install

And it works fine for me.它对我来说很好用。

[Update] The steps below are for OS X 10.10 (Yosemite). [更新]以下步骤适用于 OS X 10.10 (Yosemite)。 Those experiencing this because of an upgrade to 10.11 (El Capitan) seem need to only run sudo xcode-select --install as described in the accepted answer.那些因为升级到 10.11 (El Capitan) 而遇到这种情况的人似乎只sudo xcode-select --install按照已接受的答案中的描述运行sudo xcode-select --install

I found a suggestion here which indicated我在这里找到了一个建议它表明

sudo xcode-select -switch /

as the fix.作为修复。 However, this threw an error that the developer path was invalid.但是,这引发了开发人员路径无效的错误。

Instead, for me, I modified this to相反,对我来说,我将其修改为

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

(which is a mixture of the two referenced link solutions) and this worked. (这是两个参考链接解决方案的混合)并且这有效。

[Edit] [编辑]

Try using尝试使用

xcode-select --print-path

to find your developer path if /Applications/Xcode.app/Contents/Developer/ is still invalid for you.如果 /Applications/Xcode.app/Contents/Developer/ 对您仍然无效,请找到您的开发人员路径。

I know this is quite old but I got the same issue and then I fixed it by doing couple more extra steps.我知道这已经很老了,但我遇到了同样的问题,然后我通过执行更多额外步骤来修复它。 Problem came when Terminal could not find the actual path of the Command Line Tools.当终端找不到命令行工具的实际路径时,问题就出现了。

  1. If you had Xcode and then removed it, then Terminal is referring to the Command Line Tools inside the Xcode folder.如果您拥有 Xcode 然后将其删除,则终端指的是 Xcode 文件夹中的命令行工具。 Try using this command and check what your path is, xcode-select --print-path .尝试使用此命令并检查您的路径是什么, xcode-select --print-path This would most likely print /Applications/Xcode.app/Contents/Developer .这很可能会打印/Applications/Xcode.app/Contents/Developer
  2. Now to fix this, reinstall the command line tools for xcode.现在要解决此问题,请重新安装 xcode 的命令行工具。 Initially remove any previous installations using sudo rm -rf /Library/Developer/CommandLineTools .最初使用sudo rm -rf /Library/Developer/CommandLineTools删除任何以前的安装。
  3. Then install the command line tools sudo xcode-select --install Now the final step, change the path for the CLT to the actual path using sudo xcode-select -switch /Library/Developer/CommandLineTools/ this will fix it.然后安装命令行工具sudo xcode-select --install现在最后一步,使用sudo xcode-select -switch /Library/Developer/CommandLineTools/将 CLT 的路径更改为实际路径,这将修复它。

I started getting the same error after i update macOS Mojave to macOS Catalina.将 macOS Mojave 更新为 macOS Catalina 后,我开始遇到相同的错误。

I just installed few command lines in Terminal,我刚刚在终端中安装了几个命令行,

 1. $ sudo gem install cocoapods
 2. $ sudo xcode-select --install
 3. $ chsh -s /bin/zsh

Then,然后,

Xcode -> Preferences -> Locations -> Command Line Tools and confirm you have current Xcode version selected there.

And it works fine with me.它对我来说很好用。 Thanks!!谢谢!!

I resolved the issue with the below steps.我通过以下步骤解决了这个问题。

Xcode -> Preferences -> Locations -> Command Line Tools -> Select the command tool matching your Xcode version. Xcode -> Preferences -> Locations -> Command Line Tools ->选择与您的 Xcode 版本匹配的命令工具。

For me the solution was as easy as reinstalling Xcode.对我来说,解决方案就像重新安装 Xcode 一样简单。

It was pointed out here: https://superuser.com/a/981126这里指出: https : //superuser.com/a/981126

You can (re)install Xcode via command line like the answer above suggest, or directly from the App Store.您可以像上面建议的答案一样通过命令行(重新)安装 Xcode,或者直接从 App Store 安装。

I too had the same issue after upgrading to OS X EI Captian.升级到 OS X EI Captian 后,我也遇到了同样的问题。 I just installed xcode-select using sudo xcode-select --install我刚刚使用sudo xcode-select --install

sudo xcode-select -switch /对我sudo xcode-select -switch /

I had faced the same issue when i removed one of the two Xcode installed.当我删除安装的两个 Xcode 之一时,我遇到了同样的问题。

I have solve this issue by Switching the path using terminal like below我已经通过使用如下终端切换路径解决了这个问题

$ sudo xcode-select --switch (drag Xcode here to get a path) $ sudo xcode-select --switch(将 Xcode 拖到此处以获取路径)

eg sudo xcode-select --switch /Applications/Xcode\\ 10.1.app例如 sudo xcode-select --switch /Applications/Xcode\\ 10.1.app

Partial diagnosis: https://github.com/microsoft/vcpkg/issues/8781#issuecomment-547248760部分诊断: https : //github.com/microsoft/vcpkg/issues/8781#issuecomment-547248760

It seems that upgrading from one MacOS version to another either uninstalls some dev tools or it moves them to another path, and this breaks compatibility with any tool using the environment variable that points to the old location where the tools were located.似乎从一个 MacOS 版本升级到另一个版本会卸载一些开发工具,或者将它们移动到另一条路径,这会破坏与使用指向工具所在旧位置的环境变量的任何工具的兼容性。

sudo xcode-select --install

Using the install command worked for me, but it is not clear whether this simply downloaded and unpacked files and then skipped installation and simply updated an environment variable or whether it physically installed the files at the expected path.使用 install 命令对我有用,但不清楚这是否只是下载并解压缩文件然后跳过安装并简单地更新环境变量,或者是否将文件物理安装在预期路径上。 (Or it could have made links to the new folder path). (或者它可以链接到新文件夹路径)。

Testing my theory, I probe the folder structure with ls (I should have done this before using the install command):测试我的理论,我用ls探测文件夹结构(我应该在使用 install 命令之前这样做):

rej@Ryans-MacBook-Air:~$ ls /Library/Developer/CommandLineTools/usr/bin/
rej@Ryans-MacBook-Air:~$ ls -la /Library/Developer/CommandLineTools/usr/bin/
total 243776
drwxr-xr-x  124 root  wheel   3.9K Oct 28 23:03 ./
drwxr-xr-x    7 root  admin   224B Oct 28 23:05 ../
lrwxr-xr-x    1 root  wheel    64B Oct 28 23:03 2to3@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/2to3
lrwxr-xr-x    1 root  wheel    68B Oct 28 23:03 2to3-3.7@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/2to3-3.7
-rwxr-xr-x    1 root  wheel   116K Sep  5 22:51 DeRez*
-rwxr-xr-x    1 root  wheel    31K Sep  5 22:51 GetFileInfo*
-rwxr-xr-x    1 root  wheel    33K Sep  5 22:51 ResMerger*
-rwxr-xr-x    1 root  wheel   126K Sep  5 22:51 Rez*
-rwxr-xr-x    1 root  wheel    31K Sep  5 22:51 SetFile*
-rwxr-xr-x    1 root  wheel    32K Sep  5 22:51 SplitForks*
-rwxr-xr-x    1 root  wheel    41K Sep  5 22:51 ar*
-rwxr-xr-x    1 root  wheel    40K Sep  5 22:51 as*
-rwxr-xr-x    1 root  wheel    27K Sep  5 22:51 asa*
-rwxr-xr-x    1 root  wheel   216K Sep  5 22:51 bison*
-rwxr-xr-x    1 root  wheel   159K Sep  5 22:51 bitcode_strip*
lrwxr-xr-x    1 root  wheel     5B Oct 28 23:03 c++@ -> clang
-rwxr-xr-x    1 root  admin    31K Sep  5 22:51 c89*
-rwxr-xr-x    1 root  admin    31K Sep  5 22:51 c99*
lrwxr-xr-x    1 root  wheel     5B Oct 28 23:03 cc@ -> clang
-rwxr-xr-x    1 root  wheel    80M Sep  5 22:51 clang*
lrwxr-xr-x    1 root  wheel     5B Oct 28 23:03 clang++@ -> clang
-rwxr-xr-x    1 root  wheel   125K Sep  5 22:51 cmpdylib*
-rwxr-xr-x    1 root  wheel   154K Sep  5 22:51 codesign_allocate*
lrwxr-xr-x    1 root  wheel    17B Oct 28 23:03 codesign_allocate-p@ -> codesign_allocate
-rwxr-xr-x    1 root  admin   3.3K Aug 16 06:55 cpp*
-rwxr-xr-x    1 root  wheel    36K Sep  5 22:51 ctags*
-rwxr-xr-x    1 root  wheel   150K Sep  5 22:51 ctf_insert*
-rwxr-xr-x    1 root  wheel    30M Sep  5 22:51 dsymutil*
lrwxr-xr-x    1 root  wheel    14B Oct 28 23:03 dwarfdump@ -> llvm-dwarfdump
-rwxr-xr-x    1 root  wheel   477K Sep  5 22:51 dwarfdump-classic*
-rwxr-xr-x    1 root  wheel   211K Sep  5 22:51 dyldinfo*
-rwxr-xr-x    1 root  wheel   239B Sep  5 19:18 easy_install-3.7*
-rwxr-xr-x    1 root  wheel   572K Sep  5 22:51 flex*
-rwxr-xr-x    1 root  wheel   572K Sep  5 22:51 flex++*
lrwxr-xr-x    1 root  wheel     3B Oct 28 23:03 g++@ -> gcc
-rwxr-xr-x    1 root  wheel   101K Aug 16 07:31 gatherheaderdoc*
-rwxr-xr-x    1 root  admin    27K Sep  5 22:51 gcc*
lrwxr-xr-x    1 root  wheel     8B Oct 28 23:03 gcov@ -> llvm-cov
-rwxr-xr-x    1 root  wheel   2.4M Sep  5 22:51 git*
lrwxr-xr-x    1 root  wheel     3B Oct 28 23:03 git-receive-pack@ -> git
-rwxr-xr-x    1 root  wheel   1.4M Sep  5 22:51 git-shell*
lrwxr-xr-x    1 root  wheel     3B Oct 28 23:03 git-upload-archive@ -> git
lrwxr-xr-x    1 root  wheel     3B Oct 28 23:03 git-upload-pack@ -> git
-rwxr-xr-x    1 root  wheel   148K Sep  5 22:51 gm4*
-rwxr-xr-x    1 root  wheel   166K Sep  5 22:51 gnumake*
-rwxr-xr-x    1 root  wheel    98K Sep  5 22:51 gperf*
-rwxr-xr-x    1 root  wheel    33K Sep  5 22:51 hdxml2manxml*
-rwxr-xr-x    1 root  wheel   158K Aug 16 07:31 headerdoc2html*
-rwxr-xr-x    1 root  wheel    73K Sep  5 22:51 indent*
-rwxr-xr-x    1 root  wheel   142K Sep  5 22:51 install_name_tool*
-rwxr-xr-x    1 root  wheel   2.5M Sep  5 22:51 ld*
-rwxr-xr-x    1 root  wheel   230B Aug 16 07:13 lex*
-rwxr-xr-x    1 root  wheel   163K Sep  5 22:51 libtool*
-rwxr-xr-x    1 root  wheel    73K Sep  5 22:51 lipo*
-rwxr-xr-x    1 root  wheel   332K Sep  5 22:51 lldb*
-rwxr-xr-x    1 root  wheel   3.6M Sep  5 22:51 llvm-cov*
-rwxr-xr-x    1 root  wheel   7.9M Sep  5 22:51 llvm-dwarfdump*
-rwxr-xr-x    1 root  wheel   9.8M Sep  5 22:51 llvm-nm*
-rwxr-xr-x    1 root  wheel    11M Sep  5 22:51 llvm-objdump*
-rwxr-xr-x    1 root  wheel    40K Sep  5 22:51 llvm-otool*
-rwxr-xr-x    1 root  wheel   1.6M Sep  5 22:51 llvm-profdata*
-rwxr-xr-x    1 root  wheel   2.9M Sep  5 22:51 llvm-size*
-rwxr-xr-x    1 root  wheel   3.5K Aug 16 07:19 lorder*
-rwxr-xr-x    1 root  wheel   148K Sep  5 22:51 m4*
-rwxr-xr-x    1 root  wheel   166K Sep  5 22:51 make*
-rwxr-xr-x    1 root  wheel   7.7K Aug 16 07:16 mig*
lrwxr-xr-x    1 root  wheel     7B Oct 28 23:03 nm@ -> llvm-nm
-rwxr-xr-x    1 root  wheel   142K Sep  5 22:51 nm-classic*
-rwxr-xr-x    1 root  wheel   171K Sep  5 22:51 nmedit*
lrwxr-xr-x    1 root  wheel    12B Oct 28 23:03 objdump@ -> llvm-objdump
lrwxr-xr-x    1 root  wheel    10B Oct 28 23:03 otool@ -> llvm-otool
-rwxr-xr-x    1 root  wheel   644K Sep  5 22:51 otool-classic*
-rwxr-xr-x    1 root  wheel   138K Sep  5 22:51 pagestuff*
-rwxr-xr-x    1 root  wheel   221B Sep  5 19:18 pip3*
-rwxr-xr-x    1 root  wheel   221B Sep  5 19:18 pip3.7*
-rwxr-xr-x    1 root  wheel    32K Sep  5 22:51 projectInfo*
lrwxr-xr-x    1 root  wheel    66B Oct 28 23:03 pydoc3@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/pydoc3
lrwxr-xr-x    1 root  wheel    68B Oct 28 23:03 pydoc3.7@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/pydoc3.7
lrwxr-xr-x    1 root  wheel    67B Oct 28 23:03 python3@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/python3
lrwxr-xr-x    1 root  wheel    74B Oct 28 23:03 python3-config@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/python3-config
lrwxr-xr-x    1 root  wheel    69B Oct 28 23:03 python3.7@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/python3.7
lrwxr-xr-x    1 root  wheel    76B Oct 28 23:03 python3.7-config@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/python3.7-config
lrwxr-xr-x    1 root  wheel    70B Oct 28 23:03 python3.7m@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/python3.7m
lrwxr-xr-x    1 root  wheel    77B Oct 28 23:03 python3.7m-config@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/python3.7m-config
lrwxr-xr-x    1 root  wheel    66B Oct 28 23:03 pyvenv@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/pyvenv
lrwxr-xr-x    1 root  wheel    70B Oct 28 23:03 pyvenv-3.7@ -> ../../Library/Frameworks/Python3.framework/Versions/3.7/bin/pyvenv-3.7
lrwxr-xr-x    1 root  wheel     7B Oct 28 23:03 ranlib@ -> libtool
-rwxr-xr-x    1 root  wheel    70K Sep  5 22:51 resolveLinks*
-rwxr-xr-x    1 root  wheel    85K Sep  5 22:51 rpcgen*
-rwxr-xr-x    1 root  wheel    56K Sep  5 22:51 segedit*
lrwxr-xr-x    1 root  wheel    12B Oct 28 23:03 size@ -> size-classic
-rwxr-xr-x    1 root  wheel   125K Sep  5 22:51 size-classic*
-rwxr-xr-x    1 root  admin   138K Sep  5 22:51 stapler*
-rwxr-xr-x    1 root  wheel   126K Sep  5 22:51 strings*
-rwxr-xr-x    1 root  wheel   179K Sep  5 22:51 strip*
-rwxr-xr-x    1 root  wheel   330K Sep  5 22:51 svn*
-rwxr-xr-x    1 root  wheel   118K Sep  5 22:51 svnadmin*
-rwxr-xr-x    1 root  wheel   105K Sep  5 22:51 svnbench*
-rwxr-xr-x    1 root  wheel    64K Sep  5 22:51 svndumpfilter*
-rwxr-xr-x    1 root  wheel    71K Sep  5 22:51 svnfsfs*
-rwxr-xr-x    1 root  wheel    98K Sep  5 22:51 svnlook*
-rwxr-xr-x    1 root  wheel    70K Sep  5 22:51 svnmucc*
-rwxr-xr-x    1 root  wheel    89K Sep  5 22:51 svnrdump*
-rwxr-xr-x    1 root  wheel   122K Sep  5 22:51 svnserve*
-rwxr-xr-x    1 root  wheel    90K Sep  5 22:51 svnsync*
-rwxr-xr-x    1 root  wheel    44K Sep  5 22:51 svnversion*
-rwxr-xr-x    1 root  wheel    90M Sep  5 22:51 swift*
lrwxr-xr-x    1 root  wheel     5B Oct 28 23:03 swift-autolink-extract@ -> swift
-rwxr-xr-x    1 root  admin   6.1M Sep  5 22:51 swift-build*
-rwxr-xr-x    1 root  admin   734K Sep  5 22:51 swift-build-tool*
-rwxr-xr-x    1 root  wheel   687K Sep  5 22:51 swift-demangle*
lrwxr-xr-x    1 root  wheel     5B Oct 28 23:03 swift-format@ -> swift
-rwxr-xr-x    1 root  admin   6.1M Sep  5 22:51 swift-package*
-rwxr-xr-x    1 root  admin   6.1M Sep  5 22:51 swift-run*
-rwxr-xr-x    1 root  wheel    61K Sep  5 22:51 swift-stdlib-tool*
-rwxr-xr-x    1 root  admin   6.1M Sep  5 22:51 swift-test*
lrwxr-xr-x    1 root  wheel     5B Oct 28 23:03 swiftc@ -> swift
-rwxr-xr-x    1 root  wheel    12M Sep  5 22:51 tapi*
-rwxr-xr-x    1 root  wheel    41K Sep  5 22:51 unifdef*
-rwxr-xr-x    1 root  wheel   2.9K Aug 16 07:19 unifdefall*
-rwxr-xr-x    1 root  wheel    63K Sep  5 22:51 unwinddump*
-rwxr-xr-x    1 root  wheel    49K Sep  5 22:51 vtool*
-rwxr-xr-x    1 root  wheel    45K Sep  5 22:51 xml2man*
-rwxr-xr-x    1 root  wheel   135B Aug 16 07:22 yacc*

It is apparent that the files are physically located at that folder location and the installer installed missing components.很明显,这些文件实际上位于该文件夹位置,并且安装程序安装了缺少的组件。 The fact that MacOS's upgrade process uninstalls my development environment is unfriendly and Apple should be reprimanded. MacOS 的升级过程卸载了我的开发环境的事实是不友好的,Apple 应该受到谴责。

I got a similar error running Homebrew for the first time after upgrading from macOS Mojave v10.14 to Catalina v10.15.从 macOS Mojave v10.14 升级到 Catalina v10.15 后,我第一次运行 Homebrew 时遇到了类似的错误。

It's never a good idea to run commands without understanding what's wrong with your installation of Homebrew and what the commands actually do.在不了解 Homebrew 安装有什么问题以及这些命令实际上做了什么的情况下运行命令绝不是一个好主意。 Your first and best option is to run brew doctor .您的第一个也是最好的选择是运行brew doctor This command will not only tell you if something is wrong but also how to fix the problem.此命令不仅会告诉您是否有问题,还会告诉您如何解决问题。 In my case it showed:就我而言,它显示:

Warning: Your Xcode is configured with an invalid path.
You should change it to the correct path:
  sudo xcode-select -switch /Applications/Xcode.app

Once you fix the problem(s), run brew doctor again.解决问题后,再次运行brew doctor Basically, repeat the process until you get the all clear message.基本上,重复这个过程,直到你得到所有明确的信息。

In some cases, you get something like:在某些情况下,您会得到类似的信息:

Unbrewed dylibs/header files/static libraries were found in /usr/local/....

This will happen if you've installed software outside Homebrew that also use the same location to store their files.如果您在 Homebrew 之外安装了同样使用相同位置来存储文件的软件,就会发生这种情况。 In many cases, it's safe to ignore these warnings.在许多情况下,忽略这些警告是安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM