How to Install Git on Ubuntu 18.04
Before starting the process it will be better to know the conventions which will be used while installing Git.
- # - requires given Linux commands to be executed with root privileges either directly as a root user or by use of the sudo command
- $ - requires given Linux commands to be executed as a regular non-privileged user
Install Git from Repository
First step is to open a terminal window. Copy & 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:
# apt update # apt-get install git
You will see a page like this:
To confirm that you have installed Git correctly run the following command:
# git --version
The output will be like this:
git version 2.17.0
Now it’s time to set your personal information. Enter the following commands to add your name and email:
# git config --global user.name "W3docs" # git config --global user.email info@.w3docs.com
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:
[ .. ] [user] user.name=W3docs email@example.com [ .. ]
Note that 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 the 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 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.
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.
$ sudo apt update $ sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
Next, by visiting the Git Source Code Mirror choose the version of Git you want.
Choose "master" branch then click on the "Tags" list and select your preferred Git version.
Avoid to choose release candidate (rc) versions, because they may have unstable nature.
Then, click on "Clone or download" which will open a new window. Right click on "Download ZIP" and choose "Copy link address."
After that, go back to your terminal, set wget command for downloading Git zip package using the copied link download address. It will be like this:
$ wget https://github.com/git/git/archive/v2.19.0.zip
Unzip the file that you downloaded and move into the resulting directory with the following command:
$ unzip $ cd git-2.19.0
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.
$ make prefix=/usr/local all $ sudo make prefix=/usr/local install
To confirm that you have installed Git successfully run the following command:
$ git --version
You will get an output like this:
git version 2.19.0
Now it’s time to set up Git and provide user information by using the git config command:
$ git config --global user.name "W3docs" $ git config --global user.email "firstname.lastname@example.org"
The result will be like this:
user.name=W3docs email@example.com ...
If you want to see all the configuration items that have been set previously, use git config --list command.
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.