Linux环境的git安装有多种方法:1,yum install git*,这样的方法是有局限性,据说yum源中安装的git版本是1.7.1,Github等需要的Git版本最低都不能低于1.7.2,我的虚拟机系统版本是CentOS6,yum源里是没有git可供下载的,所以我们现在考虑方法2或者方法3;2, 云端下载git版本,然后解压编译。3,网上下载git版本,然后导入Linux的指定目录下,解压编译
下面的方法都是方法2/3需要经历的过程:
1.安装yum依赖包
需要拥有一定的权限,这里我用的是root权限,
yum install zlib-devel
yum install openssl-devel
yum install perl
yum install cpio
yum install expat-devel
yum install gettext-devel
yum install autoconf
2.下载git源码
wget https://github.com/git/git/archive/v2.3.0.zip
unzip v2.3.0.zip
cd git-2.3.0
3.编译安装git
将其安装在“/usr/local/git”目录下。
make prefix=/usr/local/git all
make prefix=/usr/local/git install
这里有可以会报错:
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-MakeMaker package.
然后再重新编译安装git:
make prefix=/usr/local/git all
make prefix=/usr/local/git install
4.配置环境变量
进入环境变量配置文件:vim /etc/profile
pATH里添加git的指定路径:我的路径是,/usr/local/git/bin
source /etc/profile:这个命令是让修改的文件生效
完了之后查看git是否安装成功:git –version
5.生成SSH密钥过程
[root@localhost bin]# git config –global user.name “oscar.xie”
[root@localhost bin]# git config –global user.email “oscar.xie@amoby.com”
[root@localhost bin]# cd ~/.ssh
-bash: cd: /root/.ssh: No such file or directory
[root@localhost bin]# ssh-keygen -t rsa -C “oscar.xie@amoby.com”
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 这里输入回车
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase): 这里输入回车
Enter same passphrase again: 这里输入回车 3个回车输入表示密码为空!
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
74:e9:ef:c5:f3:73:df:93:51:42:92:4b:ad:c4:c5:f5 “oscar.xie@amoby.com”
The key’s randomart image is:
+–[ RSA 2048]—-+
| . =…|
| .* + .|
| . oo = E|
| . o o . .|
| S . ..|
| . . . |
| . + o|
| . . *o|
| . O|
+—————–+
[root@localhost bin]# cd ~/.ssh
[root@localhost .ssh]# ll
total 8
-rw——-. 1 root root 1679 Nov 19 19:37 id_rsa
-rw-r–r–. 1 root root 407 Nov 19 19:37 id_rsa.pub