0
0

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 1 year has passed since last update.

GitをCentOS7にインストールする手順

Last updated at Posted at 2023-02-17

作業環境

OS・ミドルウェア バージョン
CentOS CentOS Linux release 7.6.1810 (Core)
Virtual Box 6.0.8 r130520 (Qt5.6.3)
Vagrant 2.2.4

導入方法

centOSにGitをインストールする最も簡単な方法はyumを利用する方法になるが、それでは古いバージョンのGitがインストールされてしまう。
今回はyumは使わずにソースコードからインストールを行う。

最新バージョンのGitをダウンロードする

最新版GitのURLは こちら から最新バージョン(git-○○○.tar.gz)を調べる。
※今回は「git-2.9.5.tar.gz」で進める。

# ダウンロードする場所へ移動
$ cd /usr/local/src/

# ダウンロード
$ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz

wgetがない場合はインストールする。

$ sudo yum install wget

ビルドに必要なパッケージをインストール

・openSSL
  暗号をサポートするためのツールキット。
・cURL
  FTP,HTTP,Gopher,TelnetおよびDictの各サーバからそれぞれサポートされているプロトコルを使用してファイルを取得するツール。
・expat
  XMLを解析するために使われる高速XMLパーサライブラリ。
・gcc
  GNUプロジェクトが開発および配布している、さまざまなプログラミング言語のコンパイラ集。
・perl-ExtUtils-MakeMaker
  Makefileを自動で生成するスクリプトを動かすためのモジュール。

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

develというのはdevelopmentバージョンで無印のものは正式バージョンになる。
 develには開発に必要なヘッダファイルが含まれている。
 ヘッダファイルがないと自分でソースコードからアプリケーションをインストールしたい場合に困ることがある。

ソースコードのビルド

makeコマンドでビルドする。
※prefixを使うことでインストール先を指定する。

# ファイルを解凍する
$ tar xvzf git-2.9.5.tar.gz

# 解凍したファイルでビルド
$ cd git-2.9.5
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install

エラーが出る場合

ここまででインストールしたもの以外に足りないものがある場合は都度インストールしていく。

# make prefix=/usr/local all
GIT_VERSION = 2.9.0
    * new build flags
    CC credential-store.o
/bin/sh: cc: command not found
make: *** [credential-store.o] Error 127

この場合はgccが入っていない。
新たにインストールする。

$ sudo yum install gcc

インストールできたか確認

$ git --version
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?