目录
Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。Git 与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持。很多yum源上自动安装的git版本为1.7.1,而Github及其他使用Coding管理项目时需要的Git版本最低都不能低于1.7.2 。比如公司里用的yum源中的git版本只有1.8,因为要安装Bitbucket7.6版本,要求Git版本为2.19及以上,所以我们一般不用yum -y install git
这种方法,而是下载git源码编译安装比较新的版本。如下是在RHEL7上编译安装GIt的步骤:
1.查看系统自带Git版本
[root@localhost ~]$ git --version
git version 1.8.3.1
系统自带Git版本为1.8,版本过低,无法继续bitbucket的安装
2.卸载系统自带Git
[root@localhost ~]$ yum remove git //删除系统自带Git
[root@localhost ~]$ git --version //再次查看版本号确认已删除成功
-bash: /usr/bin/git: No such file or directory
3.去Git官网下载Git源码并解压
点击 Downloads
点击Linux/Unix
点击download a tarball
找到你需要的版本进行下载
如果嫌麻烦直接用如下下载
[root@localhost ~]$ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.20.4.tar.gz //下载git源码
[root@localhost ~]$ tar -xzvf git-2.20.4.tar.gz //解压git安装包
[root@localhost ~]$ mv git-2.20.4 /usr/src //移动到/usr/src目录下
4.编译安装Git
源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)
[root@localhost git-2.20.4]$ make configure
GEN configure
./configure prefix=/usr/local/git/
[root@localhost git-2.20.4]$ ./configure prefix=/usr/local/git/ //配置git安装路径
[root@localhost git-2.20.4]$ make && make install //编译并且安装
执行make && make install时可能会报如下错误
zlib.h: No such file or directory
此时需要安装zlib的开发包
[root@localhost ~]$ yum install zlib-devel
安装完成后,重新执行make && make install
5.将git指令添加到bash环境变量中
[root@localhost ~]$ vi /etc/profile //打开文件
#在最后一行加入如下内容
export PATH=$PATH:/usr/local/git/bin
[root@localhost ~]$ source /etc/profile //让profile配置文件立即生效
6.查看安装好的Git新版本信息
[root@localhost ~]$ git --version //查看版本号,安装成功
git version 2.20.4
如果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.20.4]$ make configure
/bin/sh: autoconf: command not found
make: *** [configure] Error 127
[root@localhost git-2.20.4]$ cd ~
[root@localhost ~]$ yum install autoconf
参考文献
链接:https://www.jianshu.com/p/be7ee68a68a6