@ledsun blog

無味の味は佳境に入らざればすなわち知れず

Ubuntuにgitをソースコードからインストールする

WSLのUbuntu 20にgitをソースコードからインストールするのに次の手順が必要でした。

手順

sudo apt install autoconf 
sudo apt install libcurl4-openssl-dev 
curl https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.21.4.tar.xz --output git-2.21-4.tar.xz
tar -xf git-2.21-4.tar.xz 
cd git-2.21.4/
make configure
./configure --prefix=/usr NO_TCLTK=1
make NO_GETTEXT=1
sudo make install NO_GETTEXT=1

2.21.4という中途半端なバージョンであることは気にしないでください。 インストールしたいバージョンのソースコードIndex of /pub/software/scm/git/ から探してください。

参考:How to install git specific version(2.7.*) on Ubuntu - Stack Overflow

トラブルシュート

以下解説というか、つまづいた点です。

make configureにはautoconfが必要です。

ないと次のエラーが出ます。

~ make configure
GIT_VERSION = 2.21.4
    GEN configure
/bin/sh: 1: autoconf: not found
make: *** [Makefile:2274: configure] Error 127

インストールします。

sudo apt install autoconf 

参考:installation - How to install autoconf - Ask Ubuntu

Tcl/Tkがない場合は環境変数NO_TCLTKが必要

ないとmakeで次のようなエラーが出ます。

    * new locations or Tcl/Tk interpreter
    GEN git-gui
    INDEX lib/
    * tclsh failed; using unoptimized loading
    MSGFMT    po/bg.msg make[1]: *** [Makefile:252: po/bg.msg] Error 127
make: *** [Makefile:2037: all] Error 2

環境変数NO_TCLTKをつけて./configureします。

./configure --prefix=/usr NO_TCLTK=1

 

gettextがない場合は環境変数NO_GETTEXTが必要

ないと次のエラーが出ます。

    SUBDIR templates
    MSGFMT po/build/locale/pt_PT/LC_MESSAGES/git.mo
/bin/sh: 1: msgfmt: not found
make: *** [Makefile:2533: po/build/locale/pt_PT/LC_MESSAGES/git.mo] Error 127

環境変数NO_GETTEXTをつけてmakeします。 Tcl/TKの時と違いmakeの環境変数であることに注意してください。

make NO_GETTEXT=1

make installの時も同じフラグをつけて実行します。 そうしないとビルドから実行されます。

sudo make NO_GETTEXT=1 install

参考:Compile Git without gettext - Stack Overflow

httpsスキーマを使うには

httpsスキーマに対応したコンパイルができていないと、次のようなエラーがでます。

~ git clone https://example.com/test.git
Cloning into 'test'...
fatal: unable to find remote helper for 'https'

httpsを使いたい場合は、makeする前にcurlの開発用ライブラリをインストールします。

sudo apt install libcurl4-openssl-dev 

参考