Introduction
Git are essential to modern software development best practices. With version control, you keep track of your software at the source level. You can track changes, revert to previous stages, and branch to create alternate versions of files and directories. Many software project files are maintained in Git repositories, and platforms such as GitHub, GitLab, and Bitbucket make it easy to share and collaborate on software development projects. This guide will show you how to install and configure Git on Ubuntu 22.04 server in two different ways: via the built-in package manager and via source. Each of these approaches brings its own benefits depending on your specific needs.
Pre-requisites
Ubuntu 22.04 host or virtual machine.
Step 1 : Installing GIT
Git is already installed in your Ubuntu 22.04 server. Verify using this
git --version
If you do not get the version number output , then proceed with the below command
sudo apt update
sudo apt install git
git --version
Step 2 Installing Git From Source
Before you begin, you need to install the software that Git depends on. This is all available in the default repositories, so you can update your local package index and then install the relevant packages.
sudo apt update
sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc
sudo mkdir tmp
cd /tmp
From the Git project website, navigate to the tarball list available at https://mirrors.edge.kernel.org/pub/software/scm/git/ and download the version you want. Use curl and output the file you download to git.tar.gz
.
curl -o git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.38.1.tar.gz
unpack the compress tarball file
tar -zxf git.tar.gz
move into GIT directory
cd git-*
make the package now
make prefix=/usr/local all
install GIT now
sudo make prefix=/usr/local install
Replace the shell process so that the version of Git you just installed will be used
exec bash
sudo git --version
Step 3 Setup GIT
sudo git config –global user.name “Your Name“
sudo git config --global user.email "youremail@domain.com"
sudo git config --list
sudo nano ~/.gitconfig
Edit the GIT Configuration file using NANO editor with your credentials.
[user]
name = Your Name
email = youremail@domain.com
Finale
You should now have Git installed and ready to use on your system.