yum安装git

安装

  1. yum -y install git

查看

  1. #查看版本,有版本说明安装成功
  2. git --version
  3. #查看帮助
  4. git --help
  5. 查看git文件所在地
  6. whereis git && which git && find / -name git

卸载与关闭

  1. #卸载
  2. yum -y remove git

安装包模式

一、安装之前

  1. 1.安装git所需的依赖
  2. yum -y install gcc-c++ zlib zlib-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
  3. #安装更多依赖
  4. #gcc
  5. #gcc-c++
  6. #zlib
  7. #zlib-devel
  8. #perl-ExtUtils-CBuilder
  9. #perl-ExtUtils-MakeMaker
  10. #curl-devel
  11. #expat-devel
  12. #gettext-devel
  13. #openssl-devel
  14. yum -y install gcc gcc-c++ curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

二、下载解压编译安装

  1. #1.下载git安装包,在root目录下执行
  2. wget https://www.kernel.org/pub/software/scm/git/git-2.2.1.tar.gz
  3. #2.解压redis安装包并且进入redis目录
  4. tar -zxvf git-2.2.1.tar.gz && cd git-2.2.1
  5. #3.编码安装
  6. ./configure --prefix=/usr/local/git && make install
  7. #以下方式使用无效 make && make prefix=/usr/local/git install

三、设置全局变量

  1. #设置暂时性全局变量
  2. export PATH=$PATH:/usr/local/git/bin
  3. 3.设置永久性全局变量
  4. 方式1:使用>>输入进文件
  5. echo 'export PATH="$PATH:/usr/local/git/bin"' >> ~/.bash_profile
  6. source ~/.bash_profile
  7. 方式2: vim ~/.bash_profile 或者 vim /etc/profile,添加下面代码
  8. PATH=$PATH:/usr/local/git/bin

使用永久性全局变量别忘了使文件生效 source ~/.bash_profile 或 source /etc/profile

查看

  1. #查看版本,有版本说明安装成功
  2. git --version
  3. #查看帮助
  4. git --help
  5. 查看git文件所在地
  6. whereis git && which git && find / -name git

卸载与关闭

  1. #卸载
  2. rm -rf /usr/local/git

使用shell安装git

请将下载的shell与下面代码保存到同一目录 git_function.sh,写入下面代码后使之生效source ./git_function.sh

  1. #!/bin/bash
  2. #function of installing git
  3. install_git(){
  4. #download the compressed package
  5. cd /usr/local/src
  6. #if compressed package is empty then download
  7. [ -f git-2.2.1.tar.gz ] || wget https://www.kernel.org/pub/software/scm/git/git-2.2.1.tar.gz
  8. check_ok
  9. tar -zxf git-2.2.1.tar.gz
  10. check_ok
  11. [ -d /usr/local/git ] && mv /usr/local/git /usr/local/git_`date +%s`
  12. cd git-2.2.1
  13. check_ok
  14. for p in expat-devel
  15. do
  16. myum $p
  17. done
  18. make prefix=/usr/local/git all
  19. make prefix=/usr/local/git install
  20. check_ok
  21. if ! grep '^git:' /etc/group
  22. then
  23. groupadd git
  24. fi
  25. if ! grep '^git:' /etc/passwd
  26. then
  27. useradd -m git -s /usr/local/git/bin/git-shell -g git
  28. fi
  29. check_ok
  30. ln -s /usr/local/git/bin/git /usr/local/bin/git
  31. echo "git is installed finish."
  32. }
  33. read -p "Enter (Y) to start installation git :" n
  34. if [ $n == 'Y' ]
  35. then
  36. echo "Start installation==============================================================================================================================>"
  37. install_git
  38. else
  39. echo "Cancel the installation."
  40. fi