git源码编译安装

作者: Yvanna_15 | 来源:发表于2017-06-25 14:18 被阅读144次

    Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
    很多yum源上自动安装的git版本为1.7.1,而Github及其他使用Coding管理项目时需要的Git版本最低都不能低于1.7.2 。所以我们一般不用yum -y install git这种方法,而是下载git源码编译安装比较新的版本。如下是在CentOS7上编译安装步骤:

    1. 删除已有的git
    [root@localhost ~]# git --version  //查看当前版本号
    git version 1.8.3.1
    [root@localhost ~]# yum remove git  //删除原有版本
    [root@localhost ~]# git --version  //再次查看版本号确认已删除成功
    -bash: /usr/bin/git: No such file or directory
    
    1. 下载git源码并解压
    [root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.9.3.tar.gz  //下载git源码
    [root@localhost ~]# tar xf git-2.9.3.tar.gz   //解压git安装包
    [root@localhost ~]# mv git-2.9.3 /usr/src   //移动到/usr/src目录下
    
    1. 编译安装
      源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)。
    [root@localhost git-2.9.3]# make configure  
    
        GEN configure
    ./configure prefix=/usr/local/git/
    [root@localhost git-2.9.3]# ./configure prefix=/usr/local/git/  //配置git安装路径
    [root@localhost git-2.9.3]# make && make install  //编译并且安装
    
    1. 将git指令添加到bash中
    [root@localhost ~]# vi /etc/profile  //打开文件
    按下字母i键进入编辑模式,在最后一行加入如下命令,加入后按Esc键退出编辑模式,并用:wq命令保存。
      export PATH=$PATH:/usr/local/git/bin
    [root@localhost ~]# source /etc/profile  //让profile配置文件立即生效
    
    1. 查看新版本
    [root@localhost ~]# git --version  //查看版本号,安装成功
    git version 2.9.3
    

    如果make的时候报错:/bin/sh: msgfmt: command not found
    则需要安装git依赖包gettext-devel命令yum install gettext-devel
    如果make的时候报错:/bin/sh: autoconf: command not found
    则需要yum install autoconf

    [root@localhost git-2.9.3]# make configure
    /bin/sh: autoconf: command not found
    make: *** [configure] Error 127
    [root@localhost git-2.9.3]# cd ~
    [root@localhost ~]# yum install autoconf
    

    相关文章

      网友评论

        本文标题:git源码编译安装

        本文链接:https://www.haomeiwen.com/subject/wtzlcxtx.html