How to Install Git on Ubuntu Linux

This brief tutorial shows students and new users how to install Git on Ubuntu 20.04 | 18.04.

Git is probably the most popular open-source, distributed version control system today. Git allows developers to keep track of projects, code changes, create and revert changes, and collaborate with other developers.

Created by Linux Torvalds, the creator of the Linux operating system, Git is now owned by Microsoft.

If you’re a student or new user looking for an easy tutorial on installing Git on Ubuntu, the steps below should be handy.

To get started with installing Git on Ubuntu, follow the steps below:

Install Git from the Repository

Git packages come ready to install from Ubuntu default repositories. You can simply run the apt-get command to install it in Ubuntu. However, the versions available in Ubuntu repositories may not be the latest.

The installation is pretty straightforward. Simply run the commands below to install Git on Ubuntu.

sudo apt update
sudo apt install git

That should download and install Git packages.

To verify that Git is installed and functioning, run the commands below

git --version

The command above will output the line below:

Output:
git version 2.25.1

You have successfully installed Git on Ubuntu.

Install Git from Source

Again, as we mentioned above, the version that comes with Ubuntu might not necessarily be the latest. To install the latest, you will want to install the build and install it from the source.

To do that, use the steps below.

First, install the required and recommended packages to build Git. Run the commands below to do that.

sudo apt update
sudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev

Next, go to the Git project page to check the latest releases. Get the release version and replace the one below if it’s newer.

wget -c https://github.com/git/git/archive/v2.32.0.tar.gz -O - | sudo tar -xz -C /usr/src

Once the download is complete, change into the source directory and run the commands below to compile and build Git.

cd /usr/src/git-*
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install

Depending on the speed of your machine, compiling should take a couple of minutes. Once done, you can verify the Git version by running the command below again.

git --version
Output:
git version 2.32.0

That should do it!

Conclusion:

This post showed you how to install Git on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report.

Frequently Asked Questions

How do I install Git on Ubuntu?

You can install Git on Ubuntu by running the commands 'sudo apt update' followed by 'sudo apt install git' in your terminal. This will install Git from the default Ubuntu repositories.

What is the latest version of Git for Ubuntu?

The latest version of Git may not be available in the default Ubuntu repositories. To install the latest version, you can download it from the Git project page and compile it from source.

How can I verify that Git is installed on my Ubuntu system?

You can verify that Git is installed by running the command 'git –version' in your terminal. This command will display the installed version of Git.

What packages do I need to install Git from source on Ubuntu?

To install Git from source, you need to install several packages including 'dh-autoreconf', 'libcurl4-gnutls-dev', 'libexpat1-dev', and others. You can install these packages using the command 'sudo apt install '.

Can I uninstall Git from Ubuntu if I no longer need it?

Yes, you can uninstall Git from Ubuntu by running the command 'sudo apt remove git'. This will remove Git from your system, but you can always reinstall it later if needed.

Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *