install git ubuntu

Git is an open-source version control system originally developed to maintain the Linux kernel project. At present, it’s the most popular version control system thanks to its top-tier performance, security, and flexibility. We’ll cover different ways to install Git on Ubuntu, as well as some basic steps to get started with it in this article.

Install Using Apt

The easier method is to install Git from the Ubuntu repository. First, update the package index to ensure you install the latest Git version.

sudo apt update

Use apt to install Git and all the required dependencies.

sudo apt install -y git-all

After the installation completes, check the installed version with

git version

Install Git from Source

Installing Git with apt is super quick and convenient, but if you want the latest Git version, you’ll need to build it from source. For reference, the Ubuntu repo has the 2.34.1 package while the latest release that you can build from source is version 2.39.2.

Step 1: Install Dependencies

First, install the libraries that Git depends on.

sudo apt install -y dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev install-info asciidoc xmlto docbook2x

If you haven’t built a package from source before this, you may also need to install make first.

sudo apt install -y make

Step 2: Download Git Source Code

We’ll download git-2.39.2 as it’s the current latest release. You can also go to the Git index on the kernel site to browse and download a different version.


Step 3: Compile and Install Git

Extract the tarball and go to the source code directory.

tar -zxf git-2.39.2.tar.gz
cd git-2.39.2

Now, install Git by running the following commands in the shown order.

./configure --prefix=/usr
make all doc info
sudo make install install-doc install-html install-info

Finally, you can verify the installation again with

git -v

Getting Started with Git

After installing Git, you should first set your username and email address. You can do this by editing the config file at ~/.gitconfig, but a better way is to use the git config command as shown below.

git config --global "Anup Thapa"
git config --global "[email protected]"

Now, read the configuration file to verify the new settings.

git config --list

As for importing projects, start by initializing a Git repo in the project’s directory like so

cd ~/Desktop/newproject
git init

Take a snapshot of the working directory and store the contents in the Git repo with

git add .
git commit

With this, you’ve stored the current version of your project in Git. Beyond this, you can use the git -h or git help git commands to learn more about Git usage.

Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.