Tutorial

How To Install Git on Ubuntu 14.04

Published on April 23, 2014
English
How To Install Git on Ubuntu 14.04
Not using Ubuntu 14.04?Choose a different version or distribution.
Ubuntu 14.04

Introduction

An indispensable tool in modern software development is some kind of version control system. Version control systems allow you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch to create alternate versions of files and directories.

One of the most popular version control systems is git, a distributed version control system. Many projects maintain their files in a git repository, and sites like GitHub and Bitbucket have made sharing and contributing to code simple and valuable.

In this guide, we will demonstrate how to install git on an Ubuntu 14.04 VPS instance. We will cover how to install the software in two different ways, each of which have benefits.

This tutorial assumes you are signed in as a non-root user which you can learn how to create here.

How To Install Git with Apt

By far the easiest way of getting git installed and ready to use is by using Ubuntu’s default repositories. This is the fastest method, but the version may be older than the newest version. If you need the latest release, consider following the steps to compile git from source.

You can use the apt package management tools to update your local package index. Afterwards, you can download and install the program:

  1. sudo apt-get update
  2. sudo apt-get install git

This will download and install git to your system. You will still have to complete the configuration steps that we cover in the “setup” section, so feel free to skip to that section now.

How To Install Git from Source

A more flexible method of installing git is to compile the software from source. This takes longer and will not be maintained through your package manager, but it will allow you to download the latest release and will give you some control over the options you include if you wish to customize.

Before you begin, you need to install the software that git depends on. This is all available in the default repositories, so we can update our local package index and then install the packages:

  1. sudo apt-get update
  2. sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

After you have installed the necessary dependencies, you can go ahead and get the version of git you want by visiting the git project’s page on GitHub.

The version you see when you arrive at the project’s page is the branch that is actively being committed to. If you want the latest stable release, you should go change the branch to the latest non-“rc” tag using this button along the left side of the project header:

git change branch

Next, on the right side of the page, right-click the “Download ZIP” button and select the option similar to “Copy Link Address”:

git download zip

Back on your Ubuntu 14.04 server, you can type wget and follow it by pasting the address you copied. The URL that you copied may be different from mine:

  1. wget https://github.com/git/git/archive/v1.9.2.zip -O git.zip

Unzip the file that you downloaded and move into the resulting directory by typing:

  1. unzip git.zip
  2. cd git-*

Now, you can make the package and install it by typing these two commands:

  1. make prefix=/usr/local all
  2. sudo make prefix=/usr/local install

Now that you have git installed, if you want to upgrade to a later version, you can simply clone the repository and then build and install:

  1. git clone https://github.com/git/git.git

To find the URL to use for the clone operation, navigate to the branch or tag that you want on the project’s GitHub page and then copy the clone URL on the right side:

git clone URL

This will create a new directory within your current directory where you can rebuild the package and reinstall the newer version, just like you did above. This will overwrite your older version with the new version:

  1. make prefix=/usr/local all
  2. sudo make prefix=/usr/local install

How To Set Up Git

Now that you have git installed, you need to do a few things so that the commit messages that will be generated for you will contain your correct information.

The easiest way of doing this is through the git config command. Specifically, we need to provide our name and email address because git embeds this information into each commit we do. We can go ahead and add this information by typing:

  1. git config --global user.name "Your Name"
  2. git config --global user.email "youremail@domain.com"

We can see all of the configuration items that have been set by typing:

  1. git config --list
git configuration
user.name=Your Name
user.email=youremail@domain.com

As you can see, this has a slightly different format. The information is stored in the configuration file, which you can optionally edit by hand with your text editor like this:

  1. nano ~/.gitconfig
~/.gitconfig contents
[user]
    name = Your Name
    email = youremail@domain.com

There are many other options that you can set, but these are the two essential ones needed. If you skip this step, you’ll likely see warnings when you commit to git that are similar to this:

Output when git username and email not set
[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

This makes more work for you because you will then have to revise the commits you have done with the corrected information.

Conclusion

You should now have git installed and ready to use on your system. To learn more about how to use Git, check out these articles:

<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 our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
4 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!

A better way is here http://stackoverflow.com/questions/19109542/installing-latest-version-of-git-in-ubuntu

Simply

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

The “Ubuntu Git Maintainers” teams provides a PPA that you can use to ensure you get the latest version.

$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git

Also, for more information about installing and configuring Git on Ubuntu you can check out this comprehensive article, https://www.simplydjango.com/posts/git-on-ubuntu/.

You DON’T want to compile against gnu-tls because is full of bugs and it won’t work on certain network configurations, i.e. EsXi. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=741293

Do this instead: http://askubuntu.com/questions/186847/error-gnutls-handshake-failed-when-connecting-to-https-servers

libexpat1-dev gettext unzip is not working!! use the following command and install git: sudo apt-get install libexpat1-dev

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!

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.