sudo apt install git
Easy? Isn’t it?
There is only a slight little problem (which might not be a problem at all) and that is the version of Git it installs.
On an LTS system, software stability is of utmost importance this is why Ubuntu 18.04 and other distributions often provide older but stable versions of software that are well-tested with the distribution release.
This is why when you check the Git version, you’ll see that it installs a version which is older than the current Git version available on Git project’s website:
abhishek@itsfoss:~$ git --version git version 2.17.1
At the time of writing this tutorial, the version available on its website is 2.25. So how do you install the latest Git on Ubuntu then?
Install latest Git on Ubuntu-based Linux distributions
One way would be to install from source code. That cool, old school method is not everyone’s cup of tea. Thankfully, there is a PPA available from Ubuntu Git Maintainers team that you can use to easily install the latest stable Git version.
sudo add-apt-repository ppa:git-core/ppa sudo apt update sudo apt install git
Even if you had installed Git using apt previously, it will get updated to the latest stable version.
abhishek@itsfoss:~$ git --version git version 2.25.0
Configure Git [Recommended for developers]
If you have installed Git for development purposes, you’ll soon start cloning repos, make your changes and commit your change.
If you try to commit your code, you may see a ‘Please tell me who you are’ error like this:
abhishek@itsfoss:~/compress-pdf$ git commit -m "update readme" *** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'abhishek@itsfoss.(none)')
This is because you haven’t configured Git with your personal information which is mandatory.
As the error already hints, you can set up global Git configuration like this:
git config --global user.name "Your Name" git config --global user.email "[email protected]"
You can check the Git configuration with this command:
git config --list
It should show an output like this:
[email protected] user.name=abhishek
This configuration is stored in ~/.gitconfig file. You may also change it manually to change the configuration.
Start learning Git
If you are new to Git, here's a quick primer into basic Git commands.
I hope this quick little tutorial helped you to install Git on Ubuntu. With the PPA, you easily get the latest Git version.
If you have any questions or suggestions, please feel free to ask in the comment section. A quick ‘thank you’ is also welcomed :)