Tutorial

How To Install Git on a CentOS 6.4 VPS

Published on October 8, 2013
How To Install Git on a CentOS 6.4 VPS
Not using CentOS 6?Choose a different version or distribution.
CentOS 6

Status: Deprecated

This article covers a version of CentOS that is no longer supported. If you are currently operating a server running CentOS 6, we highly recommend upgrading or migrating to a supported version of CentOS.

Reason: CentOS 6 reached end of life (EOL) on November 30th, 2020 and no longer receives security patches or updates. For this reason, this guide is no longer maintained.

See Instead: This guide might still be useful as a reference, but may not work on other CentOS releases. If available, we strongly recommend using a guide written for the version of CentOS you are using.

The following DigitalOcean tutorial may be of immediate interest, as it outlines installing Git on a CentOS 7 server:

Introduction


Git is an open source, distributed version control system developed by Linus Torvalds, the creator of Linux. It features trivial branching and merging, the ability to manage multiple remote repositories for a single project, and truly distributed development.

Although git is wonderful at managing large, complex projects with perhaps hundreds or thousands of contributors, it can also work extremely well for small projects with one person or a small team. This flexibility makes it a great choice for implementing version and source control for software projects of any size.

In this article, we will cover how to install git on a CentOS 6.4 server using yum, the CentOS package manager. We will then show how to install git from source in case you would like to benefit from the latest improvements.

How To Install Git Using Yum


As is the case with most Linux distributions, git is available from CentOS’s default repositories. We can install the package maintainer’s most recent version with:

sudo yum install git

You will have to type “y” to confirm the installation. Afterwards, git will be installed and ready to use.

How To Install Git from Source on CentOS


If you want the most recent version of git, you are better off downloading the most recent version from source and compiling from there.

The version in the CentOS repositories as of this writing is 1.7.1, while the latest version of git is 1.8.4, which is a significant difference.

First, we need to download compilation tools for CentOS using the following command:

sudo yum groupinstall "Development Tools"

This will install the make tools and compilers needed to transform source code into binary executables.

Once this is complete, we will need to install some extra dependencies that git needs either to build or run:

sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel

Once these are installed, you can obtain the latest version of git from the code hosted on github.com:

cd ~
wget -O git.zip https://github.com/git/git/archive/master.zip

Unzip the archive and change into the project directory:

unzip git.zip
cd git-master

We can figure the package, build the executables and documentation, and then install it with the following set of commands:

make configure
./configure --prefix=/usr/local
make all doc
sudo make install install-doc install-html

To update git at a later date, you can actually use git! Clone the git repository on github into a new directory and then build and install it, as before:

git clone git://github.com/git/git

How To Set Up Git


When you commit changes with git, it embeds your name and email address into the commit message in order to easily track changes.

If we do not configure this information ourselves, git may try to guess these values (probably incorrectly) by using your Linux username and hostname.

Give git the values you wish to use for these parameters with these commands:

<pre> git config --global user.name “<span class=“highlight”>Your Name Here</span>” git config --global user.email “<span class=“highlight”>your_email@example.com</span>” </pre>

The configuration changes will be stored in a file in your home directory. You can see them with a normal text editor:

nano ~/.gitconfig

[user]
		name = Your Name Here
		email = your_email@example.com

You can also view this information by querying git itself for the current configuration settings:

git config --list

user.name=Your Name Here
user.email=your_email@example.com

As mentioned earlier, if you forget to set up these steps, git may try to fill in these values automatically:

[master 0d9d21d] initial project version
 Committer: root 
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

Depending on your version of git, it may fail entirely:

<pre> git commit </pre> <pre> *** Please tell me who you are.

Run

git config --global user.email “you@example.com” git config --global user.name “Your Name”

to set your account’s default identity. Omit --global to set the identity only in this repository.

fatal: empty ident name (for <demo@example.(none)>) not allowed </pre>

As you can see, git is very good about telling you exactly what you should be doing.

Conclusion


You now have git installed and can start learning some basic usage. We have a few tutorials that may be good to look at:

Git is a tool that becomes immediately useful with a basic understanding, and continues to offer advantages as your knowledge grows.

<div class=“author”>By Justin Ellingwood</div>

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
5 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

You need the curl-devel package for git to be able to clone from http/https sites.

yum install curl-devel

Hello,

Simple question, I know nothing about GitHub… Is it safe to install the following git on Centos as it is written and managed by a third party?

https://github.com/MByteIO/CentOS-WordPress

Thanks in advance

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
April 2, 2014

@ hoang.kal: What version of CentOS are you using? <pre>cat /etc/redhat-release</pre>

I’ve got this message

git: /usr/local/lib/libz.so.1: no version information available (required by git)

Try to google but don’t see any solution.

Please help.

Thanks and regards, Kal

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel