CentOS 升级 Git

1
[cyc@localhost download]$ yum upgrade git

上面的常规方法显示无更新,打印一下git版本号发现是1.8.3.1,不对啊,当前git官网都到2.14.1了,感觉到这一定是一个坑,果断谷歌,果然,原因是yum仓库里的Git版本更新不及时,也找到了不少手动更新方法,那么就自己进行手动更新喽。

卸载低版本的Git

1
[cyc@localhost download]$ yum remove git

下载最新版的git包

1
[cyc@localhost download]$ wget https://github.com/git/git/archive/v2.14.1.tar.gz

解压到app目录(如果没有目录先创建)

1
[cyc@localhost download]$ tar -xzvf v2.14.1.tar.gz -C ~/app/

进入解压后的目录,安装Git

1
2
3
[cyc@localhost app]$ cd git-2.14.1/
[cyc@localhost git-2.14.1]$ make prefix=/usr/local/git all
[cyc@localhost git-2.14.1]$ make prefix=/usr/local/git install

启动编译的时候报错了,原来是编译需要的依赖库未安装

1
2
[cyc@localhost git-2.14.1]$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[cyc@localhost git-2.14.1]$ yum install gcc perl-ExtUtils-MakeMaker

安装完依赖包后重新编译OK了

添加git到环境变量

1
2
[cyc@localhost git-2.14.1]$ echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
[cyc@localhost git-2.14.1]$ source /etc/bashrc

安装OK了,验证一下

1
2
[cyc@localhost git-2.14.1]$ git --version
git version 2.14.1

收工!