How To Install Git on Ubuntu 18.04

How To Install Git on Ubuntu 18.04

Git is a popular version control system to track your software at the source level. Your projects’ files are maintained in a Git repository. Sites such as GitHub and GitLab promote software development and collaboration.

We cover how to install Git on an Ubuntu 18.04 server.


Ensure you have a non-root user with sudo privileges on an Ubuntu 18.04 server. Once the server and user are set up, we can move to the tutorial.

1. Install Git with Default Packages

Ubuntu’s default repositories offer a quick method to install Git. The version you install via the repositories may be older than the newer version available to users. If you want the latest release, use the next step to install and compile Git from the source.

The apt package management tools are used to update the local package index:

sudo apt update

You can download and install Git after the update is complete.

sudo apt install git

Use the following command to ensure that you have installed Git correctly:

git --version
git version 2.17.1

Once Git is installed successfully, you can move to step 3, Setting Up Git in the tutorial.

2. Installing Git from Source

Another method of installing Git is to compile the software from the source. The step lets you download the latest release and offer more control over some options you’d like to include.

Verify the current version of Git installed:

git --version

If Git is installed, you’ll receive an output similar to this:

git version 2.17.1

Install the software that Git depends on. It is available in the default repositories to update the local package index:

sudo apt update

After that, you can install the packages:

sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

You have installed the necessary dependencies. You can now move into the tmp directory and download your Git tarball:

cd /tmp

Use the Git project website to navigate to the tarball list available here.

Download your preferred version. Use curl and output the file downloaded to git.tar.gz.

curl -o git.tar.gz

Unpack the compressed tarball file:

tar -zxf git.tar.gz

Now move into the new Git directory:

cd git-*

You can create the package and install it with the following two commands:

make prefix=/usr/local all
sudo make prefix=/usr/local install

Replace the shell process so that the newly installed version of Git is used:

exec bash

You can check the installation was successful by using this command:

git --version
git version 2.37.1

Once Git is successfully installed, you can complete the setup.

3. Setting Up Git

We can now configure Git so that the generated commit messages contain your correct information. It will support you in building your software project.

You will use the git config command. Provide your name and email address as Git embeds this information into each commit you do.

Add the information by typing:

git config --global "Your Name"
git config --global ""

Display all configuration items set with the following command:

git config --list
Output Name

The information is stored in your Git configuration file. You can edit it by hand with your preferred text editor. The following example uses nano:

nano ~/.gitconfig
~/.gitconfig contents
  name = Your Name
  email =

To exit the nano text editor, Press CTRL + X, then Y then ENTER.

If you skip the above step, you’ll likely see warnings when you commit to Git. You may then have to revise the commits you have done with the correct information.


Git is a distributed version control system that is lightweight and secure. You can revert to previous stages and create alternate versions of files and directories.

You can create a branch of your code and split the tasks into smaller parts. It lets you merge the code back within seconds.

We looked at the steps to install Git on Ubuntu 18.04. For more tutorials on Git, check out CloudPanel tutorials.

Nikita S.
Nikita S.
Technical Writer

As a professional content writer, Nikita S. is experienced in crafting well-researched articles that simplify complex information and promote technical communication. She is enthusiastic about cloud computing and holds a specialization in digital marketing.

Deploy CloudPanel For Free! Get Started For Free!