Linux *** 作系统下安装Git(yum 方法)

Linux *** 作系统下安装Git(yum 方法),第1张

使用yum安装确实简单方便,但 yum 存在一个问题散基就是安装的版本不好控制。

以下安装的版本为1.8.3.1,这个版本太老了。

截至发布文章的时伍册候最新版本为:v2.30.0

Git 最新版本: https://github.com/git/git/releases

源码编译安装看冲橘谨这里 https://www.jianshu.com/p/d06538116a2e

直接使用以下命令

安装完成之后使用以下命令查看安装的 Git 的版本,验证是否安装成功

出现以下信息则安装成功

此方法安装 Git 的默认路径为(/usr/libexec/git-core)可以使用命令查看安装目录信息

安装目录信息如下图所示

1. linux和windows端分别安装git,其中linux中可以用yum安装

[root@node0~]#yum install git

git的默认安装路径在/usr/libexec/git-core

[root@node0 git-core]#cd /usr/libexec/git-core

[root@node0 git-core]#git --version

git version 1.7.1

2.设置linux端git的用户名和密码

[root@node0 git-core]# groupadd git

[root@node0 git-core]# useradd wang -g git

[root@node0 git-core]# passwd wang

New password:

3.在服务器端创建远程仓库

[root@node0 ~]# mkdir -p /mnt/gitrep/wjf

[root@node0 ~]# cd /mnt/gitrep/wjf/

[root@node0 wjf]# git init

Initialized empty Git repository in /mnt/gitrep/wjf/.git/

把仓库所属用户改为wang(git的用户名)

[root@node0 wjf]# chown -R wang:git .git/

注:chown将指定文件的拥有者改为指定的用户或组 -R处理指定目录以及其子目录下的所有文件

4.在windows客户端克隆仓库 

$ git clone [email protected]:/mnt/gitrep/wjf/.git

Cloning into 'wjf'...

The authenticity of host '192.168.111.60 (192.168.111.60)' can't be established.

RSA key fingerprint is SHA256:MgWCWF************************1m2tI.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '192.168.111.60' (RSA) to the list of known hosts.

[email protected]'键携岩s password:

第一次连接远程仓库,出现黑体部分,这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,键入yes,然后隐逗输入远程仓库的密码就可以了。

5.实际中也通常通过设置公钥的方式来连接远程仓库,这样就不用每次连接都需要密码了。

设置公钥:

1.在windows客户端的gitbash中生成用户私钥和公钥

$ ssh-keygen -t rsa -C "[email protected]"

在c盘用户路径下的/.ssh文件夹下会生成私钥id_rsa和公钥id_rsa.pub

2.linux端

首先 Git服务器打开RSA认证,即,修改/etc/ssh/sshd_config,将其中的以下三项打开

RSAAuthentication yes 

 PubkeyAuthentication yes 

 AuthorizedKeysFile .ssh/authorized_keys

然后,将客户端生成的公钥给到服务器端

即,将公钥给到 home/wang(git的用户名)/.ssh/authorized_keys

[root@node0 ~]# cd /home/wang

[root@node0 wang]# mkdir .ssh

[root@node0 wang]# chmod 777 .ssh

[root@node0 wang]# touch .ssh/authorized_keys

在windows客户端稿御的gitbash中 执行:

$ ssh [email protected] 'cat >>.ssh/authorized_keys' <~/.ssh/id_rsa.pub

然后在linux端:

[root@node0 wang]# chmod 600 .ssh/authorized_keys

[root@node0 wang]# chmod 700 .ssh

[root@node0 wang]# chown wang:git .ssh

[root@node0 wang]# chown wang:git .ssh/authorized_keys 

至此,以后再连接远程仓库就不需要密码了。

若仍需要密码,可以查看ssh连接日志/var/log/secure:

常见连接失败原因:Authentication refused: bad ownership or modes for directory /home/wang/.ssh 

这时需要检查该目录的所属用户和读写权限等级是否符合要求。公钥以及.ssh文件的权限应该属于git的用户和用户组,读写权限等级.ssh 700,authorized_keys 600.

用git --version命令检查是否已经安装

2

在CentOS5的版本,由于yum源中没有git,所以需要预先安装一系列的依赖包。在CentOS6的yum源中已经有git的版本了,可以直接使用yum源进行安装。

3

yum -y install git

但是yum源中安装的git版本是1.7.1,Github等需要的Git版本最低都不能低于1.7.2 。梁配告所以我们一般不用上面的方法,而是下载git源码编译安装。

END

编译安装git

1

首先更新系统

yum  -y update

更新完成之后有6.5变成6.7了

2

安装依赖的包

yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

3

下载git源码并解压

$ wget https://github.com/git/git/archive/v2.3.0.zip

$ unzip v2.3.0.zip

$ cd git-2.3.0

4

编译安装:

将其安装在“/usr/local/git”目录下。

make prefix=/usr/local/git all

make prefix=/usr/local/git install

因为服务器时间不对编译的过程中报错如下图,使用ntpdate自动校正系统时间。报错“Writing perl.mak for Git make[2]: *** [perl.mak] Error 1”,请重启apache服务,service httpd restart。

5

编译完成之后使用git --version 查看git版本,居然卖帆还是1.7.1,这是因为它默认使用了"/usr/bin"下的git。

你可以用下面的命令查看git所在的路径:

$ whereis git

git: /usr/bin/git /usr/local/git /usr/share/man/man1/git.1.gz

6

我们要把编译安装的git路径放到环境变量里,让它替换"/usr/bin"下的git。为此我们可以修改“/etc/profile”文件(或者/etc/bashrc文件)。

vim /etc/profile

然后在文件的最后一行,添加下面的内容,然后保存橡明退出。

export PATH=/usr/local/git/bin:$PATH

7

不想重启系统,使用source命令立即生效

source /etc/profile

8

然后再次使用git --version 查看git版本,发现输出2.3.0,表明安装成功。

END


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12539945.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存