Skip to content

How to Install Git on Ubuntu 18.04

The easiest way for installing Git on your computer is visiting the page Git downloads and choosing download for Linux where the latest stable upstream Git version is provided. Also, read how to Install Git on Mac and on Windows.

Install Git from Repository

First step is to open a terminal window.

  1. Copy and paste the following into the terminal window and hit Enter. You may be prompted to enter your password. With the update complete, you can download and install Git:

Update local package index before install git, Install git in ubuntu

bash
sudo apt update

Update local package index before install git, Install git in ubuntu

bash
sudo apt-get install git
  1. To confirm that you have installed Git correctly run the following command:

get git version

bash
git --version

The output will be like this:

bash
git version 2.17.0
  1. Now it’s time to set your personal information. Enter the following commands to add your name and email:

set personal information git

bash
git config --global user.name "W3docs"
git config --global user.email [email protected]
  1. As you configure the reference into Git, you can open a Git configuration file where you will come up with the user details like this:
bash
[ .. ]
[user]
          user.name=W3docs
          user.email[email protected]
[ .. ]

DANGER

The version you install via these repositories may be older than the newest version currently available. If you need the latest release, consider the next method.

Install Git from Source

In case you wish to install the latest git version you will have to install Git from the source code.

Compiling the software from source is a more flexible method for installing Git. This method will take longer time, but it will allow you to download the latest release and will give you some control over the options.

  1. Before you start, you have to install the software that Git depends on. So you can update your local package index and then install the packages.

update local package index, install the packages

bash
sudo apt update

update local package index, install the packages

bash
sudo apt install make libssl-dev zlib1g-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
  1. Next, by visiting the Git Source Code Mirror choose the version of Git you want.
  2. Choose "master" branch then click on the "Tags" list and select your preferred Git version.

TIP

Avoid choosing release candidate (RC) versions, because they may have an unstable nature.

GitVersion
4. Then, click on "Code" which will open a new window. Right-click on "Download ZIP" and choose "Copy link address." <div class="responsive-image">GitDownload</div> 5. After that, go back to your terminal, set the wget command for downloading Git zip package using the copied link download address. It will be like this:

downloading git zip package

bash
wget https://github.com/git/git/archive/v2.19.0.zip
  1. Unzip the file that you downloaded and move into the resulting directory with the following command:

Unzip the file, change directory

bash
unzip v2.19.0.zip
cd git-2.19.0
  1. Now you are ready to install Git. Follow these two commands which will compile the formerly downloaded git source code and will install git binaries on your Ubuntu 18.04 Linux system.

compile downloaded git source code ,install git binaries on ubuntu

bash
make prefix=/usr/local all
sudo make prefix=/usr/local install
  1. To confirm that you have installed Git successfully run the following command:

get git version

bash
git --version

You will get an output like this:

bash
git version 2.19.0

Now it’s time to set up Git and provide user information by using the git config command:

set personal information git

bash
git config --global user.name "W3docs"
git config --global user.email "[email protected]"

The result will be like this:

bash
user.name=W3docs
user.email[email protected]
...

If you want to see all the configuration items that have been set previously, use the git config command with the --list option. And if you want to change the details you provided, change the settings by editing the main .gitconfig git configuration file located within your home directory.

Dual-run preview — compare with live Symfony routes.