Git is the most popular distributed version control system. It used to track changes in source code during software development. It allows to collaborate with programmers, revert to previous changes and create branches. In this tutorial, you will learn how to install Git on Ubuntu system.
You must have logged in with non-root user account with sudo privileges.
Install Git on Ubuntu
Git is available at Ubuntu default apt repository so we will install from there. It’s always recommended to install packages from Ubuntu default repository.
So first of all we need to update apt package manager index using below command:
sudo apt update
Once the list is updated execute the below command to install Git:
sudo apt install git
You can verify the installation by typing:
It will show output like below:
git version 2.11.0
That’s all. You have successfully installed Git version on you Ubuntu system.
Installing Git from a Source
Another installation method is to compile the software from source. It will allow you to download the latest release and to do customization. But you can’t manage Git package from
apt package manager.
Before you start, you need to install necessary software which Git required. These all are available from default Ubuntu repository. Execute below commands:
sudo apt update
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
After that, you can go ahead and get the version of Git you want by visiting the Git project’s mirror on GitHub and copy the latest release link address that ends in .zip
Now we will download Git source to /tmp directory on your Ubuntu system. Move to /tmp directory by typing:
Use the wget command to download the archive file as git.zip:
sudo wget https://github.com/git/git/archive/v2.21.0.zip -O git.zip
Once download is finished, unzip the downloaded file and move to the git source directory by typing:
Now, you can compile and install Git by typing these two commands:
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
Again, you can verify installation by typing:
It should show installed version of Git as given below:
git version 2.21.0
Later, if you have need to upgrade to a newer version, you can repeat the installation process.
Setting Up Git
Now your Git is installed and you need to configure it by setting up email address and username:
git config --global user.name "Your Name" git config --global user.email "youremail@ yourdomain.com"
You can see entered details by typing:
git config --list
These settings are stored at
~/.gitconfig file and you can see content as below:
[user] name = Your Name email = email@example.com
You can make other git configuration changes by using
git config command or you can edit the
~/.gitconfig file manually.
Finally, you have learned how to install Git on your Ubuntu server and how to Setting up Git. You can learn more about Git at Pro Git Book.
If you face any problem at installation time, leave a comment below.