Centos7安装git

在Centos上安装软件时,我都是先更新一下系统的yum源,保持yum源是比较新的。

yum update

下面进入今日的主题,安装git:

1.下载源码包
查看系统yum源中的git的版本,发现是比较老的版本,于是采用源码包编译安装。

cd /usr/local/src
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz

2.编译安装

cd /usr/local/src
tar -zxvf git-2.9.0.tar.gz 
cd /usr/local/src/git-2.9.0

#安装到 /usr/local/git
./configure prefix=/usr/local/git

make && make instal 报错

[root@iZbp1fuxiq5o2qp7z60ydpZ git-2.9.0]# make && make install
    CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:40:18: fatal error: zlib.h: No such file or directory
 #include <zlib.h>

解决方法:

#安装依赖
yum -y install zlib zlib-devel

再次执行make,仍然报错

/usr/bin/perl Makefile.PL PREFIX='/usr/local/git' INSTALL_BASE='' --localedir='/usr/local/git/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] Error 2
make: *** [perl/perl.mak] Error 2

解决办法:

#安装下面的依赖
yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker cpan

再次执行make & make install,编译安装成功

3.创建git用户,并将/usr/local/git所属组和所属主修改成git

useradd git

chown -R git:git /usr/local/git

4.将git加到系统环境变量里面

export GIT_HOME=/usr/local/git
export PATH=$GIT_HOME/bin:$PATH

5.初始化仓库

git init --bare mt-front.git

#下面是几种克隆方式
git clone git@xx.xx.xx.xx:/home/git/repository/mt-front.git
git clone ssh://git@xx.xx.xx.xx:/home/git/repository/mt-front.git
git clone http://git@xx.xx.xx.xx:/home/git/repository/mt-front.git

本地clone的时候会报错

  • 提示git-upload-pack命令不存在
bash: git-upload-pack: command not found
#解决
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
  • 提示git-receive-pack命令不存在
bash: git-receive-pack: command not found
ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack

7.配置git记住密码,在git的全局配置文件gitconfig文件中添加下面的配置:

[credential]
    helper = store
[user]
    name = nick
    email = nick@da.com

相关文章

此处评论已关闭