357

I've just set up a new machine with Ubuntu Oneiric 11.10 and then run

apt-get update
apt-get upgrade
apt-get install git

Now if I run git --version it tells me I have git version 1.7.5.4 but on my local machine I have the much newer git version 1.7.9.2

I know I can install from source to get the newest version, but I thought that it was a good idea to use the package manager as much as possible to keep everything standardized.

So is it possible to use apt-get to get a newer version of git, and what is the right way to do it?

5 Answers 5

680

Here are the commands you need to run, if you just want to get it done:

sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com A1715D88E1DF1F24 40976EAF437D05B5 3B4FE6ACC0B21F32 A6616109451BBBF2
sudo apt-get update
sudo apt-get install git -y
git --version

As of Dec 2018, I got git 2.20.1 that way, while the version in the Ubuntu Xenial repositories was 2.7.4.

If your system doesn't have add-apt-repository, you can install it via:

sudo apt-get install python-software-properties software-properties-common
10
  • 34
    Useful for git on the Windows' Linux subsystem too
    – dumbledad
    Commented Aug 17, 2017 at 13:45
  • 3
    It works on ubuntu 16.04 LTS Commented Mar 6, 2018 at 6:06
  • 2
    Can this ppa be trusted since they are not part of the official git team?
    – Ryuu
    Commented Oct 11, 2019 at 14:05
  • 8
    @Ryuu: PPA seems pretty official to me. It's listed at git-scm.com/download/linux, and git-scm.com is the official site for Git, per github.com/git. Commented Jan 5, 2021 at 22:17
  • 2
    can confirm this works on windows 10 WS2 as of 31-08-2021
    – Michahell
    Commented Aug 31, 2021 at 11:39
116

You have several options:

  1. Either wait until the version you need is present in the repository you use.
  2. Compile your own version and create a deb.
  3. Find a repository that provides the version you need for your version of your distribution(e.g. Git PPA).
  4. If you don't need any particular feature from the newer version, stay with the old one.

If a newer version is available in the repositories you use, then apt-get update && apt-get upgrade (as root) updates to the latest available version.

For those who don't know what a PPA is, link

3
  • 2
    +1 for the PPA. Otherwise compile from source and use checkinstall to cleanly install a .deb
    – Axel Knauf
    Commented Mar 7, 2012 at 15:54
  • 5
    The OP specifically asked for using the package manager, so only #3 applies. Commented Aug 30, 2016 at 5:02
  • should you then remove the old git installed, if you use another repository?
    – Pandian Le
    Commented May 5, 2021 at 18:09
10

Doing a search for "git ppa" gives Git stable releases. See instructions for installing here. You can also install the package by downloading directly from the web page, and installing with dpkg -i.

5

To update git on Ubuntu 12.04 just follow this line of commands:

sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git -y
git --version
-5

You can do this by homebrew in the easiest way:

install homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

upgrade git:

brew upgrade git
1
  • 1
    The question has the tag [ubuntu] so a macOS solution does not help the OP, especially since they explicitly ask to do it using apt-get Commented Apr 28, 2020 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .