Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

How To Install Git on Ubuntu 18.04

Table Of Contents


    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Installing Git with Default Packages](#installing-git-with-default-packages
    – [Installing Git from Source](#installing-git-from-source
    – [Setting Up Git](#setting-up-git
    – [Conclusion](#conclusion

    ## Introduction

    The most popular version of control systems which are currently available is [Git](https://en.wikipedia.org/wiki/Git. In Git repository, many project files are maintained, and also sites like [GitHub](https://github.com/, [GitLab](https://about.gitlab.com/, and [Bitbucket](https://bitbucket.org/ help to facilitate software development project sharing and collaboration.

    In this guide, We have described How to Install Git on Ubuntu 18.04 server.

    ## Prerequisites

    You should have access to an Ubuntu 18.04 server and created a non-root user account with sudo privileges by following our guide, [Initial server setup with Ubuntu 18.04](https://systemongrid.com/support/guides/how-to-do-initial-server-setup-with-ubuntu-18.04.

    ## Installing Git with Default Packages

    To update your local package index, Use the package management tools. After completing your update, download and install Git using below commands.

    “`
    $ sudo apt update
    $ sudo apt install git
    “`

    You can check whether you have installed Git correctly or not, by using below command.

    “`
    $ git –version
    “`

    ![gitversion](https://grid.media/assets/images/git-version-02132019.png

    Once you installed Git, then you can go through with Setting Up Git section to complete the setup.

    ## Installing Git from Source

    The best method of installing Git is to complete the software from the source. This may take a long time to maintain through your packet manager, but it allows you to download the latest version.

    First of all, you have to install the software that Git depends on. It’s all available in the default repositories so that we can update our local package index and then install the packages.

    “`
    $ sudo apt update
    $ sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
    “`

    Once you installed your necessary dependencies, now go through below URL:

    “`
    https://github.com/git/git
    “`

    Now you are in the master branch. Now click on Tags link and select your desired Git version.

    ![gittags](https://grid.media/assets/images/git-tags-02132019.png

    Now, click on the Clone or download button, then right click on the Download Zip and copy the link address that ends in .Zip

    ![gitcloneordownload](https://grid.media/assets/images/git-clone-or-download-02132019.png

    Now go back to Ubuntu server, move into the tmp directory to download temporary files.

    “`
    $ cd /tmp
    “`

    ![findcloneordownload](https://grid.media/assets/images/find-file-clone-or-download-02132019.png

    From here, you can use the wget command to install the copied Zip file link. Now specify the name for the file git.zip.

    “`
    $ wget https://github.com/git/git/archive/v2.18.0.zip -O git.zip
    “`

    Now unzip the file that you have downloaded now, and move to the resulting directory by using below command.

    “`
    $ unzip git.zip
    $ cd git-*
    “`

    Now you can make the package and install it by using below commands.

    “`
    $ make prefix=/usr/local all
    $ sudo make prefix=/usr/local install
    “`

    To know that whether the installation was successful or not, you can use git –version and you should receive relevant outputs that specify the installed versions of Git.

    If you want to upgrade the latest version, you can clone the repository and then build and install. To use for the clone operation, find the URL, navigate through to the branch or tag that you want on the Project’s GitHub page and then copy the clone URL on the right side.

    Relevant URL is:

    “`
    $ https://github.com/git/git.git
    “`

    Now you can change to your home directory, and use git clone on the URL you just copied.

    “`
    $ cd ~
    $ git clone https://github.com/git/git.git
    “`

    It will create a new directory in the current directory where you can rebuild the package and reinstall the newer version. This may overwrite your older version with the new version.

    “`
    $ cd git
    $ make prefix=/usr/local all
    $ sudo make prefix=/usr/local install
    “`

    Now, you can be sure that your version of Git is up to date.

    ## Setting Up Git

    Now Git has installed, you have to configure it so that the generated commit messages will contain your correct information. This can be acquired with git config command. You need to provide your name and email address because Git embeds this information into each commit we do. We can add this information by adding the following.

    “`
    $ git config –global user.name “Your Name”
    $ git config –global user.email “youremail@domain.com”
    “`

    We can see as output below that what you have entered by using below command.

    “`
    $ git config –list
    “`

    ![gitconfigurationlist](https://grid.media/assets/images/git-config-list-02132019.png

    This is all stored in the Git configuration file, which you can optionally edit by hand in a text editor like this.

    “`
    $ vi ~/.gitconfig

    [user]
    name = Your Name
    email = youremail@domain.com
    “`
    Like this, there are many options which you can set, but these are the two important steps we needed.

    ## Conclusion

    In this guide, we have installed Git, now you can use on your system.