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.
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.
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.
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.
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
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: rootYour 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 tutorial covered how to install Git on your virtual private server. Stay tuned for a second tutorial on Git Basics.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Former Director of Community at DigitalOcean. Expert in cloud topics including LAMP Stack, CentOS, Ubuntu, MySQL, SSL certificates, and more.
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!
Thank you! Please let me know if there are any other topics you would like to see covered. =]
Hi! this only works if you are running certain versions and set ups. The command
root@nova-controller:~# apt-get install git -y Reading package lists… Done Building dependency tree Reading state information… Done Package git is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source
E: Package ‘git’ has no installation candidate
That would depend on what repos you are contacting to install packages but it should be supported, have you made any repo changes for apt?
git config --list does not work,it shows an error fatal: bad config file line 2 in /root/.gitconfig what to do now…?
In a user’s home directory the .gitconfig file is the user’s specific config variables.
You should review that file and see if you have any errors in it as whenever you run git as root that file will be referenced.
Also depending on how your application is setup you may want to consider running all of your git repos under another user who is not root for security. In that case the /root/.gitconfig would not be referenced.
How about a post commit hook, so when after I push a commit code to git repo, it will auto upload php files to the lamp/web server which is also hosted by digital ocean. Hope you will have a tutorial for this. I am a newbie.
You can set something up like that, but it kind of breaks the convention behind git, which is meant to commit changes to the repo and then delpoy the code separately.
You can use something like capistrano to automate the deployment of your git code after you have updated. This way you can do multiple commits and work with other collaborators without having to worry that each most recent commit automatically gets deployed as this can be error prone, by deploying code that hasn’t yet been thoroughly tested.
Can this work when you are using putty? I keep getting an error saying bad config file line 1
After the following instructions above,
"Opening it following a fresh Git install would reveal a completely blank page:
sudo nano ~/.gitconfig"
I misunderstood and tried editing in the next commands directly into the that file, that is, when that file was open, I type in this:
git config --global user.name "NewUser"
git config --global user.email newuser@example.com
This was not the right thing to do. Then, when I later tried trying the same things at the command prompt, it gave me an error, because I already had bad syntax in the file. I had to delete the bad config file lines before the commands would work at the command prompt:
git config --global user.name "NewUser"
git config --global user.email newuser@example.com
I believe this may answer one of the queries/problems asked above too.
Also, should the quotes around “NewUser” in the same example be there or not, or do they matter? They are not shown around the email example of “newuser@example.com”
Thank you for the great tutorial! I’m using ubuntu 11.04 and it worked just fine.
Part 2 and Part 3 of this excellent series. https://www.digitalocean.com/community/articles/how-to-use-git-effectively https://www.digitalocean.com/community/articles/how-to-use-git-branches
I was having problems with these instructions on Ubuntu 12.04.
This seems to have worked better for me: sudo apt-get -y install git-core
Hope this helps if anyone is having issues.
For me, this post seemed to be a bit outdated. I’m running Ubuntu 12.04LTS. To update the .gitconfig file, I had to write the file in the format shown at this link: https://gist.github.com/bvsatyaram/1500350
@yeosamuelh: Yes, you should wrap the username w/quotes; and the e-mail address should <b><u>not</u></b> be wrapped w/quotes.
This doesn’t work. I just created a new droplet running Ubuntu 12.04 and the command: apt-get install git-core fails because it can’t fetch some archives:
[beta:~] root$ apt-get install git-core
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
fakeroot libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libc-dev-bin libdpkg-perl
libfile-fcntllock-perl libitm1 libquadmath0 manpages-dev
Use ‘apt-get autoremove’ to remove them.
The following extra packages will be installed:
git git-man libcurl3-gnutls
Suggested packages:
git-daemon-run git-daemon-sysvinit git-doc git-el git-arch git-cvs git-svn git-email git-gui gitk gitweb
The following NEW packages will be installed:
git git-core git-man libcurl3-gnutls
0 upgraded, 4 newly installed, 0 to remove and 1 not upgraded.
Need to get 241 kB/7,042 kB of archives.
After this operation, 15.8 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Err http://archive.ubuntu.com/ubuntu/ quantal-updates/main libcurl3-gnutls amd64 7.27.0-1ubuntu1.2
404 Not Found [IP: 91.189.92.200 80]
Err http://security.ubuntu.com/ubuntu/ quantal-security/main libcurl3-gnutls amd64 7.27.0-1ubuntu1.2
404 Not Found [IP: 91.189.91.14 80]
Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/c/curl/libcurl3-gnutls_7.27.0-1ubuntu1.2_amd64.deb 404 Not Found [IP: 91.189.91.14 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
I tried the --fix-missing with no luck.
Any ideas?
@la: As the error says:
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
Run <pre>sudo apt-get update</pre> first.
@KamalNasser Thank you! I completely missed that it. I tried --fix-missing with no luck. But apt-get update did the trick. Best.
bad config file line 1 in /root/.gitconfig. how can I fix that? Any help?
For those that are getting errors, make sure you type it like this: git config --global user.email “newuser@example.com” see the quotes. See this guide if you’re using GitHub: https://help.github.com/articles/set-up-git#platform-linux
I had a lot of trouble getting this going, until I realized that your fonts suck. Distinguishing between l and 1 are very difficult unless you closely inspect it. For anyone having trouble pay close attention to the l’s and 1’s when installing the dependancies.
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…
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
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
Another way to get the latest version of git in Ubuntu is using the Ubuntu Git Maintainers PPA:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo install git
sudo apt-get upgrade
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.