yum安装git
安装
yum -y install git
查看
#查看版本,有版本说明安装成功
git --version
#查看帮助
git --help
查看git文件所在地
whereis git && which git && find / -name git
卸载与关闭
#卸载
yum -y remove git
安装包模式
一、安装之前
1.安装git所需的依赖
yum -y install gcc-c++ zlib zlib-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
#安装更多依赖
#gcc
#gcc-c++
#zlib
#zlib-devel
#perl-ExtUtils-CBuilder
#perl-ExtUtils-MakeMaker
#curl-devel
#expat-devel
#gettext-devel
#openssl-devel
yum -y install gcc gcc-c++ curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker
二、下载解压编译安装
#1.下载git安装包,在root目录下执行
wget https://www.kernel.org/pub/software/scm/git/git-2.2.1.tar.gz
#2.解压redis安装包并且进入redis目录
tar -zxvf git-2.2.1.tar.gz && cd git-2.2.1
#3.编码安装
./configure --prefix=/usr/local/git && make install
#以下方式使用无效 make && make prefix=/usr/local/git install
三、设置全局变量
#设置暂时性全局变量
export PATH=$PATH:/usr/local/git/bin
3.设置永久性全局变量
方式1:使用>>输入进文件
echo 'export PATH="$PATH:/usr/local/git/bin"' >> ~/.bash_profile
source ~/.bash_profile
方式2: vim ~/.bash_profile 或者 vim /etc/profile,添加下面代码
PATH=$PATH:/usr/local/git/bin
使用永久性全局变量别忘了使文件生效 source ~/.bash_profile 或 source /etc/profile
查看
#查看版本,有版本说明安装成功
git --version
#查看帮助
git --help
查看git文件所在地
whereis git && which git && find / -name git
卸载与关闭
#卸载
rm -rf /usr/local/git
使用shell安装git
请将下载的shell与下面代码保存到同一目录 git_function.sh,写入下面代码后使之生效source ./git_function.sh
#!/bin/bash
#function of installing git
install_git(){
#download the compressed package
cd /usr/local/src
#if compressed package is empty then download
[ -f git-2.2.1.tar.gz ] || wget https://www.kernel.org/pub/software/scm/git/git-2.2.1.tar.gz
check_ok
tar -zxf git-2.2.1.tar.gz
check_ok
[ -d /usr/local/git ] && mv /usr/local/git /usr/local/git_`date +%s`
cd git-2.2.1
check_ok
for p in expat-devel
do
myum $p
done
make prefix=/usr/local/git all
make prefix=/usr/local/git install
check_ok
if ! grep '^git:' /etc/group
then
groupadd git
fi
if ! grep '^git:' /etc/passwd
then
useradd -m git -s /usr/local/git/bin/git-shell -g git
fi
check_ok
ln -s /usr/local/git/bin/git /usr/local/bin/git
echo "git is installed finish."
}
read -p "Enter (Y) to start installation git :" n
if [ $n == 'Y' ]
then
echo "Start installation==============================================================================================================================>"
install_git
else
echo "Cancel the installation."
fi