简体   繁体   English

无法在 Mac OS Big Sur 上运行 git

[英]Unable to run git on Mac OS Big Sur

Unable to run git on new MacBook running Big Sur无法在运行 Big Sur 的新 MacBook 上运行 git

When I try to run git, I receive the following error:当我尝试运行 git 时,我收到以下错误:

xcrun: error: unable to load libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 0x0005): could not use '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' because it is not a compatible arch). xcrun: 错误: 无法加载 libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 0x0005): could not use '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' 因为它不是兼容的拱门)。

I followed the method of forcing which architecture loads, suggested here , but still, I'm experiencing the error.我遵循了此处建议的强制加载哪些架构的方法,但仍然遇到错误。

Now, after running that suggestion I am seeing the following error:现在,运行该建议后,我看到以下错误:

manpath: error: unable to load libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 5): no suitable image found. Did find: /Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib: mach-o, but wrong architecture /Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib: mach-o, but wrong architecture). manpath:错误:无法加载 libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 5): 找不到合适的图像。确实找到了:/Library/Developer/CommandLineTools/usr/lib/libxcrun。 dylib:mach-o,但架构错误 /Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib:mach-o,但架构错误)。

I also installed homebrew prior to that error message, although I don't see how that would be related.我还在该错误消息之前安装了自制软件,尽管我不知道这将如何相关。

I really lack experience interacting with Xcode.我真的缺乏与 Xcode 交互的经验。 I feel like on my previous Mac I was just able to get up and running, without any of this hassle, but it's been awhile so perhaps I'm forgetting.我觉得在我以前的 Mac 上我只是能够启动并运行,没有任何麻烦,但已经有一段时间了,所以也许我忘记了。

How can I identify if Xcode and Command Line Tools are properly installed?如何确定 Xcode 和命令行工具是否已正确安装? If they are not, what is the recommended way to add them?如果不是,推荐的添加方式是什么?

I tried installing homebrew to see if I could use it as a work-around, and tried using it to install git, but received the following error:我尝试安装自制软件以查看是否可以将其用作解决方法,并尝试使用它来安装 git,但收到以下错误:

'brew install git '酿造安装git
Updating Homebrew...正在更新自制...
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!错误:无法在英特尔默认前缀 (/usr/local) 的 ARM 处理器上安装 Homebrew!
Please create a new installation in /opt/homebrew using one of the "Alternative Installs" from: https://docs.brew.sh/Installation请使用以下“替代安装”之一在 /opt/homebrew 中创建新安装: https://docs.brew.sh/Installation

I am on a MacBook Pro with the new M1 chip- could that be related?我正在使用带有新 M1 芯片的 MacBook Pro - 这可能是相关的吗?

ok will boy do I feel stupid- the problem was I did not have xcode installed.好吧,男孩会不会觉得我很愚蠢-问题是我没有安装 xcode。 I became confused because the error messages seemed to indicated xcode was already present and there was an xcode directory on my machine- perhaps that directory comes preinstalled in preparation for xcode?我很困惑,因为错误消息似乎表明 xcode 已经存在,并且我的机器上有一个 xcode 目录 - 也许该目录是为准备 xcode 而预先安装的?

At any rate, I solved my issue by downloading and installing xcode from the app store.无论如何,我通过从应用商店下载并安装 xcode 解决了我的问题。 Maybe this will help somebody else out也许这会帮助别人

Wow.哇。 Now I also feel really stupid.现在我也觉得自己很傻。 I also didn't have xcode installed, but I definitely thought I did because I had it installed on my old machine.我也没有安装 xcode,但我绝对认为我这样做了,因为我已经将它安装在我的旧机器上。 Apparently when transferring everything to the new machine, xcode didn't come along for the ride.显然,在将所有内容转移到新机器时,xcode 并没有出现。

Try with the following command:尝试使用以下命令:

sudo rm -r /Library/Developer/CommandLineTools

It will remove the command line tool and then immediately install the software automatically.它将删除命令行工具,然后立即自动安装软件。

  1. First, install or update the xcode in App Store首先,在 App Store 安装或更新 xcode
  2. Then, run sudo xcodebuild -license in terminal然后,在终端中运行sudo xcodebuild -license
  3. And type agree at the end of Xcode license agreements并在 Xcode 许可协议末尾键入agree

Now can use the git现在可以使用git

You can also get git from https://brew.sh/ , which I believe is fairly common!您还可以从https://brew.sh/获得 git ,我相信这很常见!

With the edit, I don't have an Apple Silicon chip to test with, but the brew docs say it should be installed to /opt/homebrew (literally untar in that path)通过编辑,我没有要测试的 Apple Silicon 芯片,但brew 文档说它应该安装到/opt/homebrew (字面意思是在该路径中解压缩)

If this is a fresh install and not upgrading an existing one, however, you may not be able to get away from having Xcode as you'll almost-certainly require some compiler or component for a few packages.但是,如果这是全新安装而不是升级现有安装,那么您可能无法摆脱 Xcode 因为您几乎肯定需要一些编译器或组件来安装一些软件包。 Existing installs should move the path or delete and rebuild (collect all your top-level packages with brew leaves && brew list -1 --cask )现有安装应移动路径或删除并重建(使用brew leaves && brew list -1 --cask收集所有顶级包)

brew install git

You may also need/want to provide a resolution for this warning if it appears如果出现此警告,您可能还需要/想要提供解决方案

hint: Pulling without specifying how to reconcile divergent branches is hint: discouraged. You can squelch this message by running one of the following hint: commands sometime before your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only> # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation.

pull.ff only is a reasonable choice, as it'll it will only do a fast-forward if you have a local conflict when attempting to pull (modified local and remote) pull.ff only是一个合理的选择,因为它只会在您尝试拉动时发生本地冲突时进行快进(修改本地和远程)

git config --global pull.ff only
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer  

Mac M1 chip use this command to change to the old xcode can help! Mac M1芯片用这个命令改成老xcode可以帮忙!

Ok, i was having this same issue with my MAC as well.好的,我的 MAC 也有同样的问题。 I was able to resolve it by running the code below.我能够通过运行下面的代码来解决它。 Works like magic.像魔术一样工作。

sudo xcode-select -switch /Library/Developer/CommandLineTools

I had this issue.我有这个问题。 Updating my mac to Big Sur 11.3 fixed it.将我的 mac 更新到 Big Sur 11.3 修复了它。

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

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