- Check for Git exists
- Install Git
- Confirm Git Installation
Pick an instance on Cloud or online terminal of Ubuntu 20+ version to this experiment. Here I'm using the KillerCoda provided Ubuntu.
Check for Git exists
This is a common requirement when you join a new project and on the Linux machine you would like to know git installed or not. We have couple of options to check it. Let's do it here:
dpkg -l git #or dpkg --list gitIn the output first 'ii' in the list means (if there are packages installed, you should see this mark) that the package is correctly installed and available. alternatively you can also try other option to check git installation on Ubuntu.
apt list git #or apt list git -aOr else you can simply use `git` it will works and provides git command help when git already installed.
gitWe can see that it is not the latest version as of now, So I wish to get installed the latest Git version on Ubuntu 24.04.
Install Git from source
1. we will download our desired verison of Git tarball, untar it, enter into the extracted directory. 2. Build git from the source code using 'make' tool 3. Run the installation using 'make install'
# install pre-requisite libraries sudo apt update sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip # Download your desired version wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.48.1.tar.gz tar -zxf git-*.tar.gz cd git-2.48.1 make prefix=/usr/local all sudo make prefix=/usr/local installNow Build steps
Confirmation of Git Installation
You know already know multiple ways to check git existing version on your Ubuntu. Let's quickly validate it git command with `--version` opton.
git --version
Auomation in mind: Git desired version on Ubuntu
Power of your brain should work smart when you look at this instructions any AI tool can gives these but we have God's given our own brain to use :)
#!/bin/bash #Measurable automation - this will calculate duration of this script execution SECONDS=0 # This can be passed as command line arugument GIT_VERSION="2.48.1" if ! sudo apt update; then echo "Failed to update package list" exit 1 fi rm -rf git* # Install the dependency libraries sudo apt install -y make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip # Download the desired git tarball wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-$GIT_VERSION.tar.gz tar -zxf git-*.tar.gz cd git-$GIT_VERSION pwd # compile the source code and install make prefix=/usr/local all sudo make prefix=/usr/local install # Validate git installed version git --version | grep ${GIT_VERSION} [ $? -eq 0 ] && echo "Git installed latest version successfully!" echo "Execution time: $SECONDS seconds"
Magical way of Git installation
The beatiful output of the above bash script is here:If you encounter any issues during the installation, you may want to check your internet connection or ensure that your package manager is up to date. Additionally, it’s helpful to refer to the official Git documentation for troubleshooting tips and further configuration options.
Please Write your valuable comments with your git installation experiments and any issues that you faced. Happy learning!!