LoginSignup
27
11

More than 1 year has passed since last update.

【GIT】"xcode-select: Failed to locate 'git', requesting installation of command line developer tools."の対処法

Posted at

はじめに

久しぶりにMacを使って個人開発をしようとしたところ、gitコマンドを叩くとタイトルにあるようなエラーが発生したので、その原因と対処法を備忘録も兼ねて簡単にまとめておきます。

原因

このエラーが出たときに、原因として考えたことは以下の2つです

  1. xcode command line toolsがインストールできていない
  2. xcode command line toolsはインストールできているが、パスが間違っている

対処法

まず1の「xcode command line toolsがインストールできていない」は既にインストールしてあるので、今回は該当しません。

もしインストールできていない場合は次のコマンドでインストールしてください

$ sudo xcodebuild -license

次に2の「xcode command line toolsはインストールできているが、パスが間違っている」についてです。
今回はこちらが該当しました。

まずは次のコマンドでパスを確認してみましょう。

$ xcode-select -p

/Applications/Xcode.app/Contents/Developer
このようなパスが返ってきた場合、パスが正しくないことが原因です。
なので次のコマンドで正しいパスを指定し直す必要があります。

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

もう1度パスを確認し、/Library/Developer/CommandLineToolsと返ってきたら
gitは使えるようになっているはずです。

27
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
11