Git, the distributed version control system, has become an essential tool for developers, enabling efficient collaboration and version management in software projects.
Installing Git on Ubuntu is quick and easy, thanks to its comprehensive package manager. Here is a step-by-step guide to installing the latest version of Git on your Ubuntu operating system.
Table of Contents
Step-by-Step: How To Install Git on Ubuntu
Before installing Git, ensure your Ubuntu system is fully updated by running the following commands in your terminal:
sudo apt update
sudo apt upgrade
This will fetch the latest stable versions of all installed packages on your Ubuntu device.
Here is a sample output of the above commands:
ubuntu@ubuntu:~$ sudo apt update
[sudo] password for ubuntu:
Get:1 http://security.ubuntu.com/ubuntu mantic-security InRelease [109 kB]
Hit:2 https://repo.nordvpn.com//deb/nordvpn/debian stable InRelease
..............
..............
Fetched 1,130 kB in 1s (807 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
20 packages can be upgraded. Run 'apt list --upgradable' to see them.
ubuntu@ubuntu:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
alsa-ucm-conf fonts-noto-color-emoji gir1.2-mutter-13 libmutter-13-0 libssh-4
mutter-common mutter-common-bin openssh-client systemd-hwe-hwdb ubuntu-desktop-minimal
ubuntu-minimal ubuntu-standard vim-common vim-tiny xserver-common xserver-xephyr
xserver-xorg-core xserver-xorg-legacy xwayland xxd
20 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
10 standard LTS security updates
Need to get 17.4 MB of archives.
After this operation, 253 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Step 1: Install Git
Once your system is updated, installing Git is straightforward as Git is available in Ubuntu’s default repositories
Enter the following command in your terminal to install the most recent stable version of Git:
sudo apt install git -y
The package manager will install Git and all required dependencies automatically. Option “-y” will automatically take the answer as yes and install the package.
Step 2: Verify the Installation
To confirm that Git has been successfully installed and is available on your system, run:
git --version
This will print out the version of Git that is now installed similar to the below output.
ubuntu@ubuntu:~$ git --version
git version 2.40.1
And that’s it! Git is now ready to use on your Ubuntu machine.
Configure Git
After Git is installed, you need to do some important configuration like setting user info and email address.
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
This information will be associated with your Git commits, allowing for the proper identification of contributors in collaborative projects.
Note that these are global settings and you can also configure project-level settings for each project.
Git is now ready, clone some open-source repos and start contributing or learning Git. If you want to learn git or other DevOps tools, subscribe to our free newsletter.
Conclusion
In summary, we learned how to install Git on Ubuntu using the apt command and configure it. We used the command ‘sudo apt install git -y‘ to install git and then used ‘git config‘ to configure global settings.