11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7にGit最新版(2.9.5)をインストール

Last updated at Posted at 2017-11-20

nvmを入れようとしたらgitがないことに気づいたので作業をまとめておきます。
公式サイトのダウンロードページに行くと

RHEL and derivatives typically ship older versions of git. You can download a tarball and build from source, or use a 3rd-party repository such as the IUS Community Project to obtain a more recent version of git.

RHELとその派生ディストリビューションについては、古いバージョンのgitを載せていることが多い。tarファイルをダウンロードしてソースからビルドするか、IUS Community Projectのようなサードパーティのリポジトリからより新しいバージョンのgitを入手することができる。

とあります。Vagrant+VirtualBox+bento/centos-7.3で立ち上げたCentOS7だとgitがそもそも入っていませんでした。

$ which git
/usr/bin/which: no git in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin)

tarファイルのダウンロード

tarファイル一覧から、git-2.9.5.tar.gzをダウンロードします。

$ cd /usr/local/src/
$ sudo wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
$ ls
git-2.9.5.tar.gz

解凍

$ sudo tar zxvf git-2.9.5.tar.gz
$ ls
git-2.9.5  git-2.9.5.tar.gz

ビルド

ビルドにはgccが必要なので先に入れておきます

$ sudo yum install -y gcc
$ which gcc
/usr/bin/gcc

makeコマンドを実行しましょう

$ cd git-2.9.5
$ sudo make prefix=/usr/local all
...
git-compat-util.h:280:25: 致命的エラー: openssl/ssl.h: そのようなファイルやディレクトリはありません
...

opensslも必要でした。赤字で怒られましたので、こちらを参考にgit導入に必要なツールをまとめてインストールします。

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

再チャレンジします

$ sudo make prefix=/usr/local all
...
    GEN git-submodule
    GEN git-web--browse
    SUBDIR perl
/usr/bin/perl Makefile.PL PREFIX='/usr/local' INSTALL_BASE='' --localedir='/usr/local/share/locale'
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3.
BEGIN failed--compilation aborted at Makefile.PL line 3.
make[1]: *** [perl.mak] エラー 2
make: *** [perl/perl.mak] エラー 2

なんかエラーが出ました。とりあえず続きをやってみます。

$ sudo make prefix=/usr/local install
    SUBDIR perl
/usr/bin/perl Makefile.PL PREFIX='/usr/local' INSTALL_BASE='' --localedir='/usr/local/share/locale'
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3.
BEGIN failed--compilation aborted at Makefile.PL line 3.
make[1]: *** [perl.mak] エラー 2
make: *** [perl/perl.mak] エラー 2

はい、無理ですね。エラー(Can't locate ExtUtils/MakeMaker.pm in ... aborted at Makefile.PL line 3.)を検索してみるとそれっぽい記事がありました。

$ sudo yum install perl-ExtUtils-MakeMaker

もう一度

$ sudo make prefix=/usr/local all

エラーが出ませんでした。インストールを実行します。

$ sudo make prefix=/usr/local install

ログがわけわかりませんがエラーは出ていないようなのでバージョンを確認します。

$ git --version
git version 2.9.5

できました。ソースからビルドをするためには必要なツールを用意するというのが重要ですね。この世の中gitがないと始まらないのでよかったです。

まとめ

$ cd /usr/local/src
$ sudo wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.g
$ sudo tar zxvf git-2.9.5.tar.gz
$ sudo yum install -y gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker
$ cd git-2.9.5
$ sudo make prefix=/usr/local all
$ sudo make prefix=/usr/local install

参考URL
CentOS7に最新のGitを導入する方法
CentOSに最新版のGitをインストール・アップデートする方法
gitをソースコードから入れる

11
9
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
11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?