Unable to run git on Mac OS Big Sur
Asked Answered
S

8

26

Unable to run git on new MacBook running Big Sur

When I try to run git, I receive the following error:

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

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

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

How can I identify if Xcode and Command Line Tools are properly installed? 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:

'brew install git
Updating Homebrew...
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the "Alternative Installs" from: https://docs.brew.sh/Installation

I am on a MacBook Pro with the new M1 chip- could that be related?

Suborder answered 5/2, 2021 at 13:22 Comment(4)
Try installing command line tools again? xcode-select --install?Tankard
thanks, I went ahead and tried this and received the following message: 'xcode-select: error: command line tools are already installed, use "Software Update" to install updates' -so it appears xcode is installed but maybe not behaving? do you happen to know the command for software update?Suborder
however, if I run softwareupdate --list no available updates are returned :-/Suborder
Try removing Xcode and reinstalling it from the App Store?Tankard
S
20

ok will boy do I feel stupid- the problem was I did not have xcode installed. 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?

At any rate, I solved my issue by downloading and installing xcode from the app store. Maybe this will help somebody else out

Suborder answered 5/2, 2021 at 21:28 Comment(1)
The error message is very misleading: "error: command line tools are already installed, use "Software Update" to install updates"Cohobate
E
18

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.

Emyle answered 3/1, 2022 at 18:12 Comment(0)
S
5

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. Apparently when transferring everything to the new machine, xcode didn't come along for the ride.

Spunky answered 16/9, 2021 at 17:18 Comment(0)
S
4
  1. First, install or update the xcode in App Store
  2. Then, run sudo xcodebuild -license in terminal
  3. And type agree at the end of Xcode license agreements

Now can use the git

Smoker answered 5/3, 2021 at 1:14 Comment(1)
This worked for me after an update to XCode 13 from 12.x.Copyholder
L
2
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer  

Mac M1 chip use this command to change to the old xcode can help!

Libelous answered 14/7, 2022 at 15:4 Comment(0)
L
1

You can also get git from https://brew.sh/, which I believe is fairly common!

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)

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. Existing installs should move the path or delete and rebuild (collect all your top-level packages with 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)

git config --global pull.ff only
Luminesce answered 5/2, 2021 at 21:59 Comment(0)
W
0

Ok, i was having this same issue with my MAC as well. I was able to resolve it by running the code below. Works like magic.

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

Wilen answered 27/9, 2022 at 13:4 Comment(0)
C
-2

I had this issue. Updating my mac to Big Sur 11.3 fixed it.

Conni answered 29/4, 2021 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.