2
2

More than 3 years have passed since last update.

MacOSでGitインストーラーのGitをアンインストールして標準(Apple git-127)に戻してみた

Last updated at Posted at 2020-05-31

Gitバージョンの確認

 MacでGitを久しぶりに使うことになり、Gitの場所とバージョンを確認すると、バージョン2.3.5でした。

$ which git
/usr/local/git/bin/git

$ git --version
git version 2.3.5

 う〜ん。いつインストールしたか思い出せない。どうやらGitインストーラーでインストールしているようだ。
(参考)Gitインストール方法の違いによるGitパスは、以下のとおり

(標準のパス)
  /usr/bin/git
(インストーラーでのGitのパス)
  /usr/local/git/bin/git
(Home-brewでのGitのパス)
  /usr/local/Cellar/git/(バージョン番号)/bin/git

Gitのアンインストール

 「Git アンインストール」でググると、「/usr/local/git」にある削除用スクリプト「uninstall.sh」で削除できると出てくるが、自分の環境にはありませんでした。(最近のインストーラーはあるのかも。確認していません。)
 このため、GitのHPからインストールされているバージョンのインストーラーのアーカイブをダウンロードして、dmg ファイルを開くと、その中に「uninstall.sh」があるので、以下のように実行します。

$ cd /Volumes/Git\ 2.3.5\ Mavericks\ Intel\ Universal 
$ sh ./uninstall.sh

 すると、

This will uninstall git by removing /usr/local/git/**/*, /etc/paths.d/git, /etc/manpaths.d/git
Type 'yes' if you are sure you wish to continue: yes
Password:
Forgot package 'GitOSX.Installer.git235Universal.git.pkg' on '/'.
Forgot package 'GitOSX.Installer.git235Universal.etc.pkg' on '/'.
Uninstalled

 アンインストールできました。

"No such file or directory"の対応

 ところが、バージョンを確認すると、

$ git --version
-bash: /usr/local/git/bin/git: No such file or directory

 「そんなものは無いよ」と言われてしまったので、which と type でファイルパスを確認するとズレている。このため、hash -r する。

$ which git
/usr/bin/git

$ type git
git is hashed (/usr/local/git/bin/git)

$ hash -r
$ git --version
git version 2.24.2 (Apple Git-127)

 最近のMacOS標準のGitは、新しいのか・・・(XcodeのアップデートでGitもアップデートされていたようだ)

最後に(home-brew)

 今後は、バージョン管理が面倒なので、home-brewでインストールして管理しようかと考えています。(home-brewでのGitインストール方法は、色々な方々が詳しく紹介されていますので、ここまでとします。)

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