Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Git on Ubuntu

Install Git from the Ubuntu repository or from source, and set your name and email.

VPS and Cloud Servers2 min read5 steps3 screenshots

What Git is

Git is the most used version control system. Its main ideas:

  1. Distributed. Every developer has a full copy of the history.
  2. Version control. Git records every change to your files.
  3. Branching. You can work on features in separate lines of the code.
  4. Staging. You choose which changes go into the next commit.
  5. Merging. Git joins the work of different people.

Method 1: Install with APT

sudo apt update
Updating the package list
sudo apt install git
Installing Git

Check it:

git --version
The Git version

Method 2: Compile from source

Use this only if you need a version that is newer than the one in Ubuntu.

Install the dependencies:

sudo apt install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext zlib1g-dev

Download the tarball of the version you want from the Git website (https://mirrors.edge.kernel.org/pub/software/scm/git/), then extract it:

tar -xzvf git-2.35.3.tar.gz
cd git-2.35.3

Configure, build and install:

make configure
./configure --prefix=/usr
make
sudo make install

Set up Git

Tell Git who you are. Git puts this in every commit:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Check your settings:

git config --list

To update Git later:

sudo apt update && sudo apt upgrade git

Why use Git

  • Version control. Track every change and go back when needed.
  • Collaboration. Branches let many people work on a project.
  • Offline work. You can commit without a connection.

Quick recap

  • sudo apt install git and check with git --version.
  • Set user.name and user.email.
  • Compile from source only for a newer version.