Introduction
“What is ”version control” and why should you care? Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
One of the most popular version control systems right now is Git. Git is a free and open source distributed version control system designed to manage everything from small to very large projects with speed and efficiency.
In this guide, we will show you how to install and configure Git on an Ubuntu server.
Prerequisites
The following are required:
- A non-root user with sudo privileges
Step 1 – Install Git
There are two main ways to install Git, shown in steps 1.1 and 1.2 below. You only need to follow one of the steps, not both.
On newer systems, Git may already be automatically installed from the default system packages. However, this version may be older than the latest version available in the official Git repository. Use git -v to check.
If Git is already installed, compare the version on your system with the latest version in the repository. If your system has an older version, you can follow «Step 1.2 – Installing Git from Source» to install the latest version.
Step 1.1 – Install Git with default packages
Ubuntu's default repositories provide a quick way to install Git. The version you install from these repositories may be older than the latest version available in the official repository.
First, use apt to update your local package list. Once the update is complete, you can download and install Git:
sudo apt update
sudo apt install gitYou can check the Git version by running the following command:
git --version
Step 1.2 – Install Git from source
A more flexible way to install Git is to compile the software from source. This takes longer and isn't maintained through your package manager, but it allows you to download the latest version and gives you some control over the options you add if you want to customize it.
Before you begin, you need to install the software dependencies.
sudo apt update
sudo apt-get install make autoconf libcurl4-gnutls-dev gettext gcc zlib1g-dev unzipAfter installing the necessary dependencies, you can get your desired Git version by visiting the Git project mirror on GitHub.
From here, make sure you are on the master branch. Click the Tags link and select the Git version you want.
To download temporary files, go to the tmp directory and you can use the wget command to install the copied zip file link.
cd /tmp
wget -O git.zip https://github.com/git/git/archive/master.zipUnzip the file and type:
unzip git.zip
cd git-*Now you can build and install the package:
make configure
./configure --prefix=/usr --without-tcltk
make all
sudo make installYou can check the Git version by running the following command:
git --version
Step 1.3 – Install Git man Pages (optional)
You can install the git man pages by typing:
cd /tmp
git clone https://github.com/gitster/git-manpages.git
cd -
sudo make quick-install-manStep 2 – Setting up Git
Now that you have Git installed, you need to configure it so that the commit messages it generates contain your correct information.
This can be achieved using the git config command. Specifically, we need to provide our name and email address because Git embeds this information in every commit we make. We can go ahead and add this information by typing:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"We can see all the configuration items:
git config --list
The information you enter is stored in your Git configuration file, which you can optionally edit with a text editor like this:
nano ~/.gitconfig
Conclusion
With Git installed and set up on your local machine, you are now ready to use Git to version control your software projects as well as contribute to open source projects that are free to the public.









