355

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?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
cwd
  • 45,389

5 Answers5

675

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
Afe
  • 103
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

Marco
  • 33,548
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.

Faheem Mitha
  • 35,108
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
techraf
  • 5,941
-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
    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 – Ciprian Tomoiagă Apr 28 '20 at 15:11