Tutorial

How To Install Git on Ubuntu 12.04

Published on August 7, 2012
How To Install Git on Ubuntu 12.04
Not using Ubuntu 12.04?Choose a different version or distribution.
Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

What the Red Means

The lines that the user needs to enter or customize will be in red in this tutorial! The rest should mostly be copy-and-pastable.

About Git

Git is a distributed version control system released to the public in 2005. The program allows for non-linear development of projects, and can handle large amounts of data effectively by storing it on the local server. This tutorial will cover two ways to install Git.

How to Install Git with Apt-Get

Installing Git with apt-get is a quick and easy process. The program installs on the virtual private server with one command:

sudo apt-get install git-core

After it finishes downloading, you will have Git installed and ready to use.

How to Install Git from Source

If you are eager to download the most recent version of Git, it is generally a good idea to install it from the source.

Quickly run apt-get update to make sure that you download the most recent packages to your VPS.

sudo apt-get update

Prior to installing Git itself, download all of the required dependancies:

sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev build-essential

Once they are installed, you can download the latest version of Git from the google code page.

wget https://git-core.googlecode.com/files/git-1.8.1.2.tar.gz

After it downloads, untar the file and switch into that directory:

tar -zxf git-1.8.1.2.tar.gz
cd git-1.8.1.2

If you want to do a global install, install it once as yourself and once as root, using the sudo prefix:

make prefix=/usr/local all
sudo make prefix=/usr/local install

If you need to update Git in the future, you can use Git itself to do it.

git clone git://git.kernel.org/pub/scm/git/git.git

How to Setup Git

After Git is installed, whether from apt-get or from the source, you need to copy your username and email in the gitconfig file. You can access this file at ~/.gitconfig.

Opening it following a fresh Git install would reveal a completely blank page:

sudo nano ~/.gitconfig

You can use the follow commands to add in the required information.

git config --global user.name "NewUser"
git config --global user.email newuser@example.com

You can see all of your settings with this command:

git config --list

If you avoid putting in your username and email, git will later attempt to fill it in for you, and you may end up with a message like this:

[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

See More

This tutorial covered how to install Git on your virtual private server. Stay tuned for a second tutorial on Git Basics.

By Etel Sverdlov

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?
 
10 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!

Good tutorial… Very useful… easy to use, well explained… :-)

The power of linux-warrior-travelers is to be alert, to get maximum effect from minimal impulse because of such great tuts 8) Thanx, Etel!

fatal: bad config file line 1 in /home/nikhil/.gitconfig

getting this problem help me

Another way to get the latest version of git in Ubuntu is using the Ubuntu Git Maintainers PPA:

If you don’t have the add-apt-repository utility

sudo apt-get install python-software-properties

Register the PPA

sudo add-apt-repository ppa:git-core/ppa

update package index

sudo apt-get update

If you don’t have git installed yet

sudo install git

Else

sudo apt-get upgrade

it is very use full…thank you…

for yeosamuelh

to fix the syntax error , you have to put this [user] before name and email properties, like this : [user] name = nafia email = amaziane.n@gmail.com

I solved it myself

Hi how can i connect with sourcetree to my git bare repo?

used to get this msg:

The program ‘git’ is currently not installed. To run ‘git’ please ask your administrator to install the package ‘git’

here is how you fix it

[code] sudo dpkg --configure -a [/code]

if you still having proble installing git

I used the first method at the top, it seemed the most idiot(me) proof and all the commands worked (I think) they threw no errors anyway but afterwards in putty all three it has “user name” and it has “email” both those lines fully typed out then under both of them but when I type “git config --list” nothing happens I just get another new line to enter stuff on no errors being thrown, what am I dong wrong, please say someone watches these comments everything has gone perfect till here, love your guys’ beginner tutorials, I couldn’t even start my first droplet without the tuts lol…

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