Git is one of the most popular version control systems. Many projects files are stored and maintained in a Git repositories such as GitHub, GitLab, and Bitbucket to facilitate software development project sharing and collaboration. You can track changes, revert to previous stages, and branch to create many versions of files and directories. In this tutorial, you will learn how to Install Git from Source Code on Ubuntu 20.04.
- User with sudo privileges
- Machine installed Ubuntu 20.04
First, you should check if you have Git command line tools installed on your machine.A few operating systems also come with Git installed, so it is worth checking before you install.
$ git --version
if Git is not installed, you will get an error as following:
-bash: git: command not found 'git' is not recognized as an internal or external command, operable program or batch file.
Now you have to install Git into your machine.
Method 1 : Install using Ubuntu Default Package Repo
Using the default Ubuntu repositories is a fast method to install Git but this version may be older than the newest version currently available. If you want to install the newest version the you should got for installation of Git from source code. In next section of this tutorial to learn how to install and compile Git from source.
First, update the local package repository and then install Git using below commands:
$ sudo apt update $ sudo apt install git
Verify the Git installation by running the following command:
$ git --version #output git version 2.25.1
After successful installation of Git, now you can move on to the Setting Up Git. Follow this to setup the git in your local machine.
Method 2 : Install Git by Compiling from Source
Compiling Git from source is very flexible method to install Git. Although this is not so easy but it will provide the latest release and give you some control over the options you include if you wish to customize.
Before you begin compiling source, you should have installed the software that Git depends on. These are all available in the default repositories, so we can update our local package repo and then install the necessary packages.
$ sudo apt update $ sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
After you have installed the necessary dependencies, you can go ahead and download the latest version of Git. Please visit Github Site on your favourite web browser to download latest git source.
On Github go to Master branch and click on Tags. Select your desired Git version. Unless you have a reason for downloading a release candidate (marked as rc0, rc-1 and so on) version, try to avoid these as these may be unstable.
Now, on the right side of the page, click on the Code, then right-click on Download ZIP and copy the link address that ends in .zip.
Back on your Ubuntu 20.04 server, move into the opt directory.
$ cd /opt
Now download the Git source file from the copied link from Github using wget command:
$ wget https://github.com/git/git/archive/v2.28.0.zip -O git.zip
Extract the file that you downloaded and move into the resulting directory using below command:
$ unzip git.zip $ cd git-2.28.0
Next, you can make install the package by using these two commands:
$ make all prefix=/usr/local $ sudo make install prefix=/usr/local
To ensure that the installation was successful, you can run below command:
Hence, you successfully installed Git from source code.
Setting Up Git
When Git successfully installed, you can now move on to the Setting Up Git section of this tutorial to complete your setup.
The easiest way of doing this is using the git config command. Specifically, you need to provide your name and email address because Git writes this information into each commit you do.
You can do this by following commands:
$ git config --global user.name "Your Name" $ git config --global user.email "[email protected]"
You can verify all of the configuration items that you have set by following:
$ git config --list #outut user.name=Your Name [email protected]
There is another method to check the configuration. There is .gitconfig (a hidden config file) that contains all this config information.
$ vi ~/.gitconfig #output [user] name = Your Name email = [email protected]
Once you’re done making changes in this file, you can exit vi by typing the :wq .
Finally, you have learned how to Install Git from Source Code on Ubuntu 20.04. Now you have Git installed in your ubuntu 20.04 and ready to use on your system.
Read Also : How To Install Jenkins on Ubuntu 20.04