How to Set Up Git on Ubuntu 22.04

By way of introduction,

Git is crucial for contemporary software development techniques. It enables you to monitor your software at its core level, allowing you to trace modifications, return to previous stages, and branch out to generate different variations of files and directories.

Git repositories are used to store files for a number of software projects, with platforms such as GitHub, GitLab, and Bitbucket making it easier to share and collaborate on these projects.

You will be taught in this guide how to install and set up Git on an Ubuntu 22.04 server using two different methods: the package manager included with the system and the source installation. Each of these methods has its own advantages based on your specific requirements.

Requirements

You will require an Ubuntu 22.04 server that has a superuser account which is not rooted.

To get started, you can refer to our initial server setup guide for Ubuntu 22.04.

Now that your server and user are all set up, you are prepared to get started.

Installing Git using the default packages.

If you want to quickly set up and start using Git, prefer a stable version that is widely used, or don’t require the latest features, then installing with default packages is the best option for you. However, if you specifically want the latest release, refer to the section on installing from source.

Chances are that Git is already installed on your Ubuntu 22.04 server. To verify, you can use the following command on your server:

  1. git –version

 

If you see a similar output as the one below, it means that Git has already been installed.

Output

git version 2.34.1

If this situation applies to you, you have the option to proceed with setting up Git. Alternatively, you may choose to refer to the next section, which explains how to install from source if you require a more current version.

If you haven’t obtained the Git version number, you can install it using the APT package manager, which is the default manager for Ubuntu.

To begin with, utilize the apt package management tools for refreshing your local package index.

  1. sudo apt update

 

Once the update is finished, you can proceed with installing Git.

  1. sudo apt install git

 

To verify that you have correctly installed Git, execute the given command and ensure that you obtain appropriate output.

  1. git –version

 

Output

git version 2.34.1

Once you have Git installed, you can proceed to the Setting Up Git section of this tutorial to finish setting it up.

Setting up Git by compiling the source code.

If you want a more adaptable way to install Git, consider building the software from source. While this process takes longer and won’t be updated through your package manager, it lets you obtain the most recent version and provides you with more freedom to customize the included options.

Please confirm the installed version of Git on the server.

  1. git –version

 

If Git is installed, the output you will receive will be similar to this.

Output

git version 2.34.1

Prior to starting, it is essential to install the necessary software that Git relies on. All these software packages are readily accessible in the default repositories. Therefore, you can first update your local package index and subsequently install the required packages.

  1. sudo apt update
  2. sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

 

Once the essential dependencies have been installed, establish a temporary directory.

  1. mkdir tmp

 

Go to your tmp directory and download the Git tarball there.

  1. cd /tmp

 

To obtain the desired version, head over to the tarball selection on the Git project website at https://mirrors.edge.kernel.org/pub/software/scm/git/. Proceed to download the preferred version, which as of now is 2.38.1. For illustrative purposes, opt for the latest version. Utilize curl to acquire the file and save it as git.tar.gz.

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

 

Extract the compressed tarball file.

  1. tar -zxf git.tar.gz

 

Afterwards, proceed to the newly created Git directory.

  1. cd git-*

 

Presently, you have the ability to create the package by executing this command.

  1. make prefix=/usr/local all

 

Creating this process may require a significant amount of time. Once the process is complete, you can install Git by entering the given command.

  1. sudo make prefix=/usr/local install

 

Replace the shell process with the newly installed Git version for usage.

  1. exec bash

 

Once you have completed this, you can verify the success of your installation by checking the version.

  1. git –version

 

Output

git version 2.38.1

Now that you have successfully installed Git, you can proceed to finalize your setup.

How to Install Git

Once you have successfully set up your Git version, it is essential to configure Git in a way that ensures your commit messages include accurate information. This will provide you with the necessary support while developing your software project.

To set up your configuration, use the git config command. In particular, you must enter your name and email address as Git incorporates this data into every commit you make. Simply input the following to include this information:

  1. git config –global user.name Your Name
  2. git config –global user.email youremail@domain.com

 

To see all the configuration items that have been set, simply type:

  1. git config –list

 

Output

user.name=Your Name user.email=youremail@domain.com

You may choose to manually edit your Git configuration file with a text editor of your preference, where the information you input will be stored. For this example, we will use the nano text editor.

  1. nano ~/.gitconfig

 

Contents of the .gitconfig file located in the home directory.
[user]
  name = Your Name
  email = youremail@domain.com

To exit the nano text editor, simply press the combination of CTRL + X, followed by Y, and finally ENTER.

There are several additional choices available, but these two are crucial. If you overlook this step, you will probably encounter warnings when committing to Git. This will result in more effort for you as you will have to subsequently revise your commits with accurate information.

In conclusion, to sum up

Git should be installed on your system by now and ready for use.

For a deeper understanding of Git usage, refer to these articles and series

  • How To Use Git Effectively
  • How To Use Git Branches
  • An Introduction to Open Source

 

 

 

more tutorials

Python Compiler Error during package installation?(Opens in a new browser tab)

Spring Boot CLI(Opens in a new browser tab)

Learn how to automate repetitive tasks using Makefiles.(Opens in a new browser tab)

The top seven Linux distributions for laptops(Opens in a new browser tab)

Set in Python(Opens in a new browser tab)

 

Leave a Reply 0

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


广告
Closing in 10 seconds
bannerAds