Linux 安裝git - 源碼安裝
如需轉載註明來源。
原文地址:https://www.cnblogs.com/qiutianyou/p/9501498.html
https://qiutianyou.gitbooks.io/qtyblog/content/Git/install.html
Git 安裝
這裏就不記錄Windows/Mac OS系統的了,直接下載對應的安裝程序,按步驟安裝即可。
Linux 安裝
登陸https://git-scm.com/download/linux
源碼安裝
1. 下載源碼
可以在另一臺電腦中下載好源碼,然後上傳至Linux服務器
https://mirrors.edge.kernel.org/pub/software/scm/git/
找到對應的版本。
2. 上傳至服務器
以git-2.9.5.tar.gz為例,將下載好的文件上傳至服務器。
scp git-2.9.5.tar.gz [email protected]:/home/tools
scp git-2.9.5.tar.gz 目標機器的用戶@目標機器ip:目標機器路徑
3. 解壓並安裝
登陸目標機器,解壓並安裝。/home/Git是指的安裝目錄
tar -zxvf git-manpages-2.9.5.tar.gz cd git-2.9.5 [root@localhost git-2.9.5]# ./configure --prefix=/home/Git [root@localhost git-2.9.5]# make && make install
4. ./configure 報錯
[root@localhost git-2.9.5]# ./configure --prefix=/home/Git configure: Setting lib to ‘lib‘ (the default) configure: Will try -pthread then -lpthread to enable POSIX Threads. configure: CHECKS for site configuration checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/home/tools/git-2.9.5‘: configure: error: no acceptable C compiler found in $PATH See `config.log‘ for more details
我的linux服務器執行報錯中看出,gcc,cc,cl.exe為no。gcc是Linux的c語言編譯器,說明我的機器中沒有安裝這些編譯器。
分別安裝以下gcc,gcc-c++,安裝成功之後在執行一下git的安裝命令
Linux [root@localhost git-2.9.5]# yum install gcc [root@localhost git-2.9.5]# yum install gcc-c++ [root@localhost git-2.9.5]# ./configure --prefix=/home/Git
5. make命令報錯
[root@localhost git-2.9.5]# make && make install
* new build flags
CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:40:18: 致命錯誤:zlib.h:沒有那個文件或目錄
#include <zlib.h>
^
編譯中斷。
make: *** [credential-store.o] 錯誤 1
缺少 zlib的頭文件, 開發包沒裝。安裝zlib
Linux [root@localhost git-2.9.5]# yum install zlib [root@localhost git-2.9.5]# yum install zlib-devel [root@localhost git-2.9.5]# yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker [root@localhost git-2.9.5]# make && make install
若無報錯則安裝成功
6.檢查git安裝是否完成
進入之前指定的安裝目錄,查看git版本,能成功則表示git安裝完成
[root@localhost bin]# cd /home/Git/bin
[root@localhost bin]# ./git --version
git version 2.9.5
7.配置環境變量
vi /etc/profile
編輯環境變量配置文件,在最後追加下面的字符串,指定bin目錄的地址
export PATH=$PATH://home/Git/bin
修改完成之後,執行命令,生效配置文件
source /etc/profile
檢查是否配置成功,可切換路徑到其他目錄中,執行 git --version。返回git版本則表示環境變量配置完成。
Linux 安裝git - 源碼安裝