码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS安装git

时间:2016-04-19 11:42:11      阅读:1033      评论:0      收藏:0      [点我收藏+]

标签:

Method #1 » 用yum源安装

[root@localhost ~]# sudo yum install git

   查看安装的git的版本号:

[root@localhost ~]# git --version
git version 1.8.3.1  

   但yum源中安装的git版本是1.8.3.1,太老了。

Method #2 » 下载git源码,编译安装

1.更新安装源:

[root@localhost ~]# yum update

2.安装git相关的依赖包:

[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

3.到git官网查看最新的版本为2.8.1:

https://git-scm.com/download/

4.下载git源码并解压:

[root@localhost ~]# wget https://github.com/git/git/archive/v2.8.1.zip
[root@localhost ~]# unzip v2.8.1.zip
[root@localhost ~]# cd git-2.8.1

5.编译安装到“/usr/local/git”目录下:

[root@localhost ~]#make prefix=/usr/local/git all
[root@localhost ~]#make prefix=/usr/local/git install 

此时,使用git --version 查看git版本,发现仍然是1.8.3.1版本。这是因为它默认使用了"/usr/bin"下的git。

[root@localhost ~]# git --version
git version 1.8.3.1

接着查看git所在的路径:

[root@localhost git-2.8.1]# whereis git
git: /usr/bin/git /usr/share/man/man1/git.1.gz

6.设置环境变量:

把编译安装的git路径放到环境变量里,让它替换"/usr/bin"下的git。为此我们可以修改“/etc/profile”文件(或者/etc/bashrc文件),在文件的最后一行(即77行)添加“export PATH=/usr/local/git/bin:$PATH”

[root@localhost ~]# vim /etc/profile

保存修改:

[root@localhost ~]# source /etc/profile

再次查看git的版本号是2.8.1:

[root@localhost ~]# git --version
git version 2.8.1  

  

 

 

CentOS安装git

标签:

原文地址:http://www.cnblogs.com/xixihuang/p/5407150.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!