スポンサーリンク

CentOS 7 yum でインストールした Git を 1.8.3 から 2.x にバージョンアップする

 

こちらの記事を参考に

 

手っ取り早く実行したコマンドを見たい方は最後まで読み飛ばしてください

 

1.Gitをアンインストール

2.gitのインストールに必要なパッケージをインストール

3.最新版のGitを探す

4.最新版のGitをダウンロード

5.Gitインストール

6.シンボリックリンクの設定

7.実行コマンドまとめ

 

1.Gitをアンインストール

[root@dev381 ~]# yum remove git
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
–> Running transaction check
—> Package git.x86_64 0:1.8.3.1-6.el7_2.1 will be erased
–> Processing Dependency: git = 1.8.3.1-6.el7_2.1 for package: perl-Git-1.8.3.1-6.el7_2.1.noarch
–> Running transaction check
—> Package perl-Git.noarch 0:1.8.3.1-6.el7_2.1 will be erased
–> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00
epel/x86_64/metalink | 4.2 kB 00:00
epel/x86_64 | 4.3 kB 00:00
epel/x86_64/updateinfo | 798 kB 00:00
epel/x86_64/primary_db | 4.8 MB 00:00
extras/7/x86_64 | 3.4 kB 00:00
extras/7/x86_64/primary_db | 191 kB 00:00
remi-safe | 2.9 kB 00:00
remi-safe/primary_db | 953 kB 00:05
updates/7/x86_64 | 3.4 kB 00:00
updates/7/x86_64/primary_db | 7.8 MB 00:00

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
git x86_64 1.8.3.1-6.el7_2.1 @base 22 M
Removing for dependencies:
perl-Git noarch 1.8.3.1-6.el7_2.1 @base 57 k

Transaction Summary
================================================================================
Remove 1 Package (+1 Dependent package)

Installed size: 22 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : git-1.8.3.1-6.el7_2.1.x86_64 1/2
Erasing : perl-Git-1.8.3.1-6.el7_2.1.noarch 2/2
Verifying : perl-Git-1.8.3.1-6.el7_2.1.noarch 1/2
Verifying : git-1.8.3.1-6.el7_2.1.x86_64 2/2

Removed:
git.x86_64 0:1.8.3.1-6.el7_2.1

Dependency Removed:
perl-Git.noarch 0:1.8.3.1-6.el7_2.1

Complete!

 

2.gitのインストールに必要なパッケージをインストール

$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

 

3.最新版のGitを探す

ここから探す

 

4.最新版のGitをダウンロード

3で見つけた最新版のGitのバージョンのURLを指定してダウンロード

$ wget https://www.kernel.org/pub/software/scm/git/git-2.2.0.tar.gz

解凍する

$ tar -zxf git-2.2.0.tar.gz

そして移動

$ cd git-2.2.0

 

5.Gitインストール

make prefix=/usr/local all
make prefix=/usr/local install

 

6.シンボリックリンクの設定

シンボリックリンクの設定をしないとgitコマンドを使ったときに”No such file or directory”と怒られます

シンボリックリンクが違うところを指しているため起こるらしい

こちら参考

$ ln -s /usr/local/bin/git /usr/bin/git

 

シンボリックリンクじゃなくてhashコマンドでも解決できるらしい

参考はこちら

 

7.まとめ

GITVERSION="2.13.3" &&
wget https://www.kernel.org/pub/software/scm/git/git-$GITVERSION.tar.gz &&
tar -zxf git-$GITVERSION.tar.gz &&
cd git-$GITVERSION &&
unset GITVERSION &&
make prefix=/usr/local all &&
make prefix=/usr/local install &&
ln -s/usr/local/bin/git /usr/bin/git && git --version

コメント

タイトルとURLをコピーしました