Установка git linux centos

How to install latest version of git on CentOS 8.x/7.x/6.x

It did not install the latest version of git on my CentOS 6. How can I update to the latest version of git for CentOS 6? The solution can be applicable to newer versions of CentOS such as CentOS 7.

Yes, it is. It’s entirely within bounds to ask a question and answer it when it’s useful info that hasn’t been addressed.

Without using external repos to upgrade Git, you can try to use yum shell commands. Here’s how I’ve upgraded from git 1.8 to git 2.24: serverfault.com/a/1045216/91648

14 Answers 14

You can use WANDisco’s CentOS repository to install Git 2.x: for CentOS 6, for CentOS 7

    Install WANDisco repo package:

yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm - or - yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm - or - yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm 

As of 02 Mar. 2020, the latest available version from WANDisco is 2.22.0.

This answer must be applied. Already applied answer with —disablerepo=base,updates doesn’t work for me.

And FWIW, as of 2016-11-08, the WANDisco version of Git is up to version 2.10; right in line with the official Git SCM releases.

As of Feb 2019, this repo seems to have stopped getting updates: latest git is v2.20.1 but the repo has only v2.18.0

Having a look at the blog here I found the solution in one of the comments. Make sure you got the rpmforge repository added to your CentOS yum and just run the flowing command:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras install git 

If you already have git installed then use:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras update git 

Note update:

Thanks to Anthony Hatzopoulos, for git v1.8x you’ll need to use git18 as in:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras install git18 

Note update 2:

Also thanks to @Axlrod for the below hint and @Hiphip for the feedback:

Change the rpmforge.repo file to have rpmforge-extras to enabled, yum update git . Otherwise it complained about dependency problems.

Note update 3:

Installing a specific version of git say 2.x I found this nice and easy-to-follow guide on how to download the GIT source and compile it yourself (and install it). If the accepted answer does not give you the version you want, try the following instructions:

(And pasted/reformatted from above source in case it is removed later)

Step 1: Install Required Packages

Firstly we need to make sure that we have installed required packages on your system. Use following command to install required packages before compiling Git source.

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

Step 2: Uninstall old Git RPM

Читайте также:  Полезные команды для linux

Now remove any prior installation of Git through RPM file or Yum package manager. If your older version is also compiled through source, then skip this step.

Step 3: Download and Compile Git Source

Download git source code from kernel git or simply use following command to download Git 2.0.4.

# cd /usr/src # wget https://www.kernel.org/pub/software/scm/git/git-2.0.4.tar.gz # tar xzf git-2.0.4.tar.gz 

After downloading and extracting Git source code, Use following command to compile source code.

# cd git-2.0.4 # make prefix=/usr/local/git all # make prefix=/usr/local/git install # # echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc # or # echo 'export PATH=$PATH:/usr/local/git/bin' > /etc/profile.d/git.sh # # source /etc/bashrc 

HINT 1: Updated method of adding compiled git bin directory to bashrc. Because echo «export PATH=$PATH:/usr/local/git/bin» >> /etc/bashrc used «» instead of », it would expand the current session’s value for $PATH instead of keeping it as a variable, and could adversely affect the entire system. At the minimum, it should use » instead of «» and should really be a separate script in /etc/profile.d/

HINT 2 (@DJB): /usr/local/git/bin before $PATH , since the older version of git was already on $PATH: export PATH=/usr/local/git/bin:$PATH

Step 4. Check Git Version

One completion of above steps, you have successfully install Git in your system. Let use following command to check git version

# git --version git version 2.0.4 

I also wanted to add that the «Getting Started» guide at the GIT website also includes instructions on how to download and compile it yourself:

This only got me git v1.7x. For git v1.8x you’ll need to use git18 as in yum —disablerepo=base,updates —enablerepo=rpmforge-extras install git18

didn’t work for me, I had to change the rpmforge.repo file to have rpmforge-extras to enabled, and then do yum update git. Otherwise it complained about dependency problems. (since it needed packages from base)

Running yum —disablerepo=base,updates —enablerepo=rpmforge-extras list | grep git only shows Git 1.7.12 for me on Centos 6.6. Perhaps they’ve removed «git18»?

wiki.centos.org/AdditionalResources/Repositories/RPMForge RPMForge/RepoForge is a dead project. It is not maintained. DO NOT USE.

Rackspace maintains the ius repository, which contains a reasonably up-to-date git, but the stock git has to first be removed.

CentOS 6 or 7 instructions (run as root or with sudo):

# retrieve and check CENTOS_MAIN_VERSION (6 or 7): CENTOS_MAIN_VERSION=$(cat /etc/centos-release | awk -F 'release[ ]*' '' | awk -F '.' '') echo $CENTOS_MAIN_VERSION # output should be "6" or "7" # Install IUS Repo and Epel-Release: yum install -y https://repo.ius.io/ius-release-el$.rpm yum install -y epel-release # re-install git: yum erase -y git* yum install -y git-core # check version: git --version # output: git version 2.24.3 

Note: git-all instead of git-core often installs an old version. Try e.g. git224-all instead.

Читайте также:  Linux mint hex editor

The script is tested on a CentOS 7 docker image ( 7e6257c9f8d8 ) and on a CentOS 6 docker image ( d0957ffdf8a2 ).

This is the only method on this page that I’ve tried (as of 7 September 2018) that ensures an up-to-date 2.x git for CentOS and also ensures a compiled git-credential-libsecret is installed, which is the safest os-native means for storing git credentials, e.g. for http[s] URLs. The currently accepted answer at the time of writing (stackoverflow.com/a/21820716/407170) does not do these things and requires you to compile yourself.

If you want to automate this using Ansible, I recommend checking out github.com/iuscommunity/automation-examples/blob/… (or github.com/iuscommunity/automation-examples for other solutions)

I found this nice and easy-to-follow guide on how to download the GIT source and compile it yourself (and install it). If the accepted answer does not give you the version you want, try the following instructions:

(And pasted/reformatted from above source in case it is removed later)

Step 1: Install Required Packages

Firstly we need to make sure that we have installed required packages on your system. Use following command to install required packages before compiling Git source.

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

Step 2: Uninstall old Git RPM

Now remove any prior installation of Git through RPM file or Yum package manager. If your older version is also compiled through source, then skip this step.

Step 3: Download and Compile Git Source

Download git source code from kernel git or simply use following command to download Git 2.5.3.

# cd /usr/src # wget https://www.kernel.org/pub/software/scm/git/git-2.5.3.tar.gz # tar xzf git-2.5.3.tar.gz 

After downloading and extracting Git source code, Use following command to compile source code.

# cd git-2.5.3 # make prefix=/usr/local/git all # make prefix=/usr/local/git install # echo 'pathmunge /usr/local/git/bin/' > /etc/profile.d/git.sh # chmod +x /etc/profile.d/git.sh # source /etc/bashrc 

Step 4. Check Git Version

On completion of above steps, you have successfully install Git in your system. Use the following command to check the git version

# git --version git version 2.5.3 

I also wanted to add that the «Getting Started» guide at the GIT website also includes instructions on how to download and compile it yourself:

Re Step 3. setting the path, I found this (serverfault.com/a/303824) works better: # echo ‘pathmunge /usr/local/git/bin/’ > /etc/profile.d/git.sh # chmod +x /etc/profile.d/git.sh

I tried on Centos 6.5 and tried latest (today) GIT version 2.5.3, and works like a charm. wget https://www.kernel.org/pub/software/scm/git/git-2.5.3.tar.gz

This allowed me to install 2.10.1 to keep parity with my git local client. Awesome set of instructions.

If you still find that git is not installed then it might be due to pathmunge. You can use following commands to add git in your environment. echo «export PATH=/usr/local/git/bin:$PATH» >> /etc/bashrc and then source /etc/bashrc

Читайте также:  Настройка rdp подключения linux

My personal preference is to build rpm packages for CentOS when installing non-standard software and replacing distributed components. For this I recommend that you use Mock to create a clean build environment.

  1. Obtain the source RPMS or a suitable SPEC file and pristine source tarball. In this case one may find source RPM packages for git2X for CentOS-6 at: http://dl.iuscommunity.org/pub/ius/archive/CentOS/6/SRPMS/ . Packages for other CentOS releases are also available.
  2. Install the necessary support software:
yum install epel-release # you need this for mock yum install rpm-build yum install redhat-rpm-config yum install rpmdevtools yum install mock 
sudo adduser builder --home-dir /home/builder \ --create-home --user-group --groups mock \ --shell /bin/bash --comment "rpm package builder" 
su -l builder rpmdev-setuptree 
~ └── rpmbuild ├── BUILD ├── RPMS ├── SOURCES ├── SPECS └── SRPMS 
wget http://dl.iuscommunity.org/pub/ius/archive/CentOS/6/SRPMS/git2u-2.5.3-1.ius.centos6.src.rpm \ -O ~/rpmbuild/SRPMS/git2u-2.5.3-1.ius.centos6.src.rpm 
cd /etc/mock rm default.cfg ln -s epel-6-x86_64.cfg default.cfg vim default.cfg 
mock --no-clean --rebuild ~/rpmbuild/SRPMS/git2u-2.5.3-1.ius.centos6.src.rpm 
ll /var/lib/mock/epel-6-x86_64/result total 34996 -rw-rw-r--. 1 byrnejb mock 448455 Oct 30 10:09 build.log -rw-rw-r--. 1 byrnejb mock 52464 Oct 30 10:09 emacs-git2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 47228 Oct 30 10:09 emacs-git2u-el-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 8474478 Oct 30 09:57 git2u-2.5.3-1.ius.el6.src.rpm -rw-rw-r--. 1 byrnejb mock 8877584 Oct 30 10:09 git2u-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 27284 Oct 30 10:09 git2u-all-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 27800 Oct 30 10:09 git2u-bzr-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 112564 Oct 30 10:09 git2u-cvs-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 436176 Oct 30 10:09 git2u-daemon-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 15858600 Oct 30 10:09 git2u-debuginfo-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 60556 Oct 30 10:09 git2u-email-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 274888 Oct 30 10:09 git2u-gui-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 79176 Oct 30 10:09 git2u-p4-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 483132 Oct 30 10:09 git2u-svn-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 173732 Oct 30 10:09 gitk2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 115692 Oct 30 10:09 gitweb2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 57196 Oct 30 10:09 perl-Git2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 89900 Oct 30 10:09 perl-Git2u-SVN-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 101026 Oct 30 10:09 root.log -rw-rw-r--. 1 byrnejb mock 980 Oct 30 10:09 state.log 
yum localinstall \ git2u-2.5.3-1.ius.el6.x86_64.rpm \ perl-Git2u-2.5.3-1.ius.el6.noarch.rpm` 
cat /etc/yum.repos.d/LocalFile.repo # LocalFile.repo # # This repo is used with a local filesystem repo. # # To use this repo place the rpm package in /root/RPMS/yum.repo/Packages. # Then run: createrepo --database --update /root/RPMS/yum.repo. # # To use: # yum --enablerepo=localfile [command] # # or to use only ONLY this repo, do this: # # yum --disablerepo=\* --enablerepo=localfile [command] [localfile] baseurl=file:///root/RPMS/yum.repo name=CentOS-$releasever - Local Filesystem repo # Before persistently enabling this repo see the priority note below. enabled=0 gpgcheck=0 # When this repo is enabled all packages in repos with priority>5 # will not be updated even when they have a more recent version. # Be careful with this. priority=5 

You also may be required to manually pre-install additional dependency packages such as perl-TermReadKey available from the usual repositories.

Источник

Оцените статью
Adblock
detector