linux实战--(4)--CentOS7安装,卸载Git GitHub

Linux实战系列文章:文章导航

Git官网提供了安装方法:https://git-scm.com/download/linux
可恶的是,对于Red Hat Enterprise Linux, Oracle Linux, CentOS, Scientific Linux, et al.这些发行版本没有最新的git,只能手动安装,当然CentOS属于其中such a shit…
官方说,这些发行版本的linux有两种安装方式
1、You can download a tarball and build from source (下载源码自己编译)
2、 3rd-party repository such as the IUS Community Project to obtain a more recent version of git (第三方RPM库安装)

分析,两种都好使,下面分别做笔记。。

1. 源码编译安装卸载(推荐)

1.1 源码编译安装

# 卸载自带的git,可忽略,git会再次作为依赖被安装
yum remove -y git

# 下载安装包,地址:https://mirrors.edge.kernel.org/pub/software/scm/git/
wget -O git-2.20.1.tar.gz  https://codeload.github.com/git/git/tar.gz/v2.20.1
#或者
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.20.1.tar.gz

# 安装依赖 , git会再次作为依赖被安装,安装后需要再次卸载
yum install -y gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel autoconf

# 编译
tar -zxvf git-2.20.1.tar.gz
cd git-2.20.1
make configure
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc

# 后续处理
git --version
# 发现还是 git 1.8.3.1 what the hell,此时要淡定,继续往下执行
yum remove -y git
git --version
# -bash: /usr/bin/git: 没有那个文件或目录
source /etc/bashrc
git --version
# git version 2.20.1
# 大功告成

1.2 卸载

源码编译的如何卸载

# 上面源码编译安装后的git如何卸载? 如下:
which -a git
# /usr/local/git/bin/git 进入父级目录
cd /usr/local/git/bin/
rm -rf git*
# 此时已经移除git的可执行文件了,然后是移除配置文件
which -a git
# /usr/bin/which: no git in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/install/apache-maven-3.6.0/bin:/usr/local/git/bin)
# 我们把 /etc/bashrc 中的git配置移除掉就可以了
vim /etc/bashrc
# 移除 “:/usr/local/git/bin”
source /etc/bashrc
which -a git
# 至此git已经成功移除

2. IUS Community Project 安装(不推荐)

之所以不推荐,是因为,笔者在后来的开发中发现这个东东会和很多的安装包冲突。mmd

2.1 安装

官网:https://ius.io/
介绍:IUS是一个社区项目,为Enterprise Linux发行版的新版精选软件提供RPM包。
项目目标

  • 为Red Hat Enterprise Linux(RHEL)和CentOS创建高质量的RPM包。
  • 上游开发人员发布新版本后,及时发布更新的RPM包。
  • 没有自动更换库存RPM包。
    命名规则
    在所有的安装包后面+u
    {name}{major_version}{minor_version}u
    eg:git2u-0:2.16.5-1.ius.centos7.x86_64
# 脚本说明:https://ius.io/GettingStarted/
# 自动安装脚本:https://setup.ius.io/
wget -O setup.ius.io.sh https://setup.ius.io/
sh setup.ius.io.sh
# 至此 IUS 安装完成

# 安装 
repoquery --whatprovides git | sort -u
rpm -q git
yum install -y git2u
git --version
# 至此,git已经安装完成了,虽然不是最新的,但是足够使用了

2.2 卸载

下面的卸载可能有问题,误信,主要是发现卸载后安装不上了,郁闷

yum remove  git2u-2.16.5-1.ius.centos7.x86_64
yum remove -y git2u
yum list installed | grep git
# 卸载所有 git2u相关的包
# yum remove git2u****
# 移除源
rm /etc/yum.repos.d/ius*
which -a git
# /usr/bin/git
rm -y /usr/bin/git*
source /etc/bashrc
# 至此git已经移除完毕
git --version
# -bash: git: 未找到命令

3. github配置

# 配置用户信息
git config --global user.name "HiAscend"
git config --global user.email "poseidon1237@163.com"

# github添加公钥
ssh-keygen -t rsa -b 4096 -C "example@163.com"
# 输入位置,直接回车默认位置
# 输入密码,直接回车,无密码
# 添加到 ssh-agent 可选
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
# 然后在github上添加证书
cat  ~/.ssh/id_rsa.pub
# 按步骤添加到github:https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/#platform-linux

# 实在不行,参考官方手册 文档很简单,我这蹩脚的英语就能看懂,相信你也能看懂
# 官方手册:https://help.github.com/articles/connecting-to-github-with-ssh/

4. Clone项目

git clone git@github.com:HiAscend/mylinux.git

如果push到github时,每次都要输入用户名和密码,请参考我的另一篇博客解决。


看这里,看这里
文章总目录:博客导航
参考文章:https://blog.csdn.net/u_ascend/article/details/85990799
https://www.cnblogs.com/yexinw/p/6401663.html
https://blog.csdn.net/qq_35573689/article/details/73223740

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值