方式一、yum安装
# yum install git
通过yum方式安装,版本比较旧,CentOS6.8上安装好是1.7.1版。如果想安装最新版或其他版本,需要使用源码编译安装的方式。
方式二、源码包安装
Part1:安装依赖库
[root@iZwz96pb4qob9lpzadqipkZ local]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel [root@iZwz96pb4qob9lpzadqipkZ local]# yum install gcc perl-ExtUtils-MakeMaker
Part2:下载源码
下载git-2.17.0.tar.gz 到 /usr/local
(查找git版本可以到https://www.kernel.org/pub/software/scm/git/下查看git的版本号自行选择下载)
[root@iZwz96pb4qob9lpzadqipkZ local]# wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.17.0.tar.gz
Part3:解压、编译和安装
[root@iZwz96pb4qob9lpzadqipkZ local]# tar -zvxf git-2.17.0.tar.gz [root@iZwz96pb4qob9lpzadqipkZ local]# cd git-2.17.0 [root@iZwz96pb4qob9lpzadqipkZ local]# make prefix=/usr/local/git all [root@iZwz96pb4qob9lpzadqipkZ local]# make prefix=/usr/local/git install
Part4:将git目录加入PATH
[root@iZwz96pb4qob9lpzadqipkZ local]# echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc [root@iZwz96pb4qob9lpzadqipkZ local]# source /etc/bashrc
Part5:创建git账号并设置密码
[root@iZwz96pb4qob9lpzadqipkZ bin]# useradd -m git [root@iZwz96pb4qob9lpzadqipkZ bin]# passwd git Changing password for user git. New password: Retype new password: passwd: all authentication tokens updated successfully.
Part6:创建git仓库并初始化
[root@iZwz96pb4qob9lpzadqipkZ www]# pwd /data/www [root@iZwz96pb4qob9lpzadqipkZ www]# mkdir -p repositories/test.git [root@iZwz96pb4qob9lpzadqipkZ www]# ls index.html index.php repositories thinkphp [root@iZwz96pb4qob9lpzadqipkZ www]# cd repositories/test.git/ [root@iZwz96pb4qob9lpzadqipkZ test.git]# git --bare init Initialized empty Git repository in /data/www/repositories/test.git/ [root@iZwz96pb4qob9lpzadqipkZ test.git]# ls branches config description HEAD hooks info objects refs
Part7:给git仓库目录设置用户和用户组并设置权限
clone地址:
ssh://git@服务器ip地址:端口/data/www/repositories/test.git
附加:以后每次新建仓库时,只需执行上面Part7、8即可!
本文为Davidvivi原创文章,转载无需和我联系,但请注明来自Davidvivi博客weixia.xin 本人微信:ww646904527,备注博客