Monday, October 3, 2022

How To Install Latest Git on Ubuntu 22.04

In this guide, we want to teach you to Install Latest Git on Ubuntu 22.04.

Git is a DevOps tool used for source code management. It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to track changes in the source code, enabling multiple developers to work together on non-linear development. Linus Torvalds created Git in 2005 for the development of the Linux kernel.

Steps To Install Latest Git on Ubuntu 22.04

To set up Git, you must log in o your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.

Installing Git From APT Repository on Ubuntu 22.04

By default, git is installed on your Ubuntu 22.04. You can verify it by checking its version:

git --version
Output
git version 2.25.1

Note: If you didn’t get a version number in your output, you can easily install git from the APT repository:

# sudo apt update
# sudo apt install git

Now you can move on to configuring the Git section.

Installing Git From Source on Ubuntu 22.04

There is another way to install Git that is more flexible and has the latest release. It is to install Git from the source. To do this, follow the steps below:

First, install the required packages on your server with the following command:

sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

Then, create a temp directory and navigate to it with the following commands:

# mkdir tmp
# cd /tmp

At this point, visit this link and download the version you want to use with the curl command:

curl -o git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.3.tar.gz

To know more about the curl command, you can visit the How To Use curl command in Linux.

Then, extract your downloaded file:

tar -zxf git.tar.gz

Switch to your Git directory:

cd git-*

Now make the package and install it with the following commands:

# make prefix=/usr/local all
# sudo make prefix=/usr/local install

It will take some time to complete.

Next, replace the shell process:

exec bash

Then, verify your Git installation on Ubuntu 22.04 by checking its version:

git --version
Output
git version 2.9.3

Configure Git on Ubuntu 22.04

At this point, you must configure Git so that the generated commit messages you make will contain the correct information and support you as you build your software project.

You must provide your name and email address because Git embeds this information into each commit you do. To do this, you can use the following commands:

# git config --global user.name "Your Name"
# git config --global user.email "[email protected]"

After setting up the user name and email ID, you can verify the details using git config --list command:

git config --list
Output
user.name=Your Name
user.email=[email protected]

All the configuration done through the git command will save the information in a file called .gitconfig in the user’s home directory. So you can also verify the configuration by checking this file using cat ~/.gitconfig command as shown below:

cat ~/.gitconfig
Output
[user]
   name=Your Name
   email=[email protected]

How To Use Git

Now that you have set up the latest Git, you can try using it by performing git clone operations from GitHub.

We can just clone a repository called wig by using git clone https://github.com/jekyc/wig.git command as shown below. This will create a directory wig in your local system and copy all the contents from the repository:

git clone https://github.com/jekyc/wig.git
Output
Cloning into 'wig'...
remote: Enumerating objects: 4240, done.
remote: Total 4240 (delta 0), reused 0 (delta 0), pack-reused 4240
Receiving objects: 100% (4240/4240), 4.47 MiB | 7.89 MiB/s, done.
Resolving deltas: 100% (2832/2832), done.
Checking connectivity... done.

Also, you can check all the subcommands available with the git command using git help -a command as shown below:

git help -a
Output
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]

available git commands in '/usr/local/libexec/git-core'

add merge-index
add--interactive merge-octopus
am merge-one-file
annotate merge-ours
apply merge-recursive
archimport merge-resolve
archive merge-subtree
bisect merge-tree
bisect--helper mergetool
blame mktag
branch mktree
.....

That’s it, you are done.

Conclusion

At this point, you learn to Install Git from the APT repository and the latest release from the source on Ubuntu 22.04. Also, you learn basic usage of it.

Hope you enjoy it.

You may be interested in these articles:

Install Caddy Web Server on Ubuntu 22.04

How To Install Tesseract OCR on Ubuntu 22.04

Install and Configure NTP Server and Client on Ubuntu 22.04

Install and Configure Nextcloud on Ubuntu 22.04

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles