tech

How to Install and Set Up Git on Ubuntu Linux (Step-by-Step Guide)

Git is the most widely used version control system, essential for developers working on personal or team projects. If you're using Ubuntu, installing and configuring Git takes just a few steps.

In this guide, you'll learn how to install Git on Ubuntu, configure it, and verify everything is working correctly.

Step 1: Update Package List

Always update your package list before installing new software. Before installing any new software, it’s a best practice to update your system’s package list. This ensures you get the latest available version of Git from the Ubuntu repositories.

sudo apt update

Step 2: Install Git on Ubuntu

Once the package list is updated, install Git using the following command:

sudo apt install git -y

The -y flag automatically confirms the installation.

Step 3: Verify Git Installation

After installation, confirm that Git has been installed successfully by checking its version:

git --version

You should see output similar to:

git version 2.x.x

This confirms Git is installed and ready to use.

Step 4: Configure Git Username and Email

Git requires your name and email address to associate commits with you. This is especially important when working with GitHub, GitLab, or Bitbucket.

Set your global username:

git config --global user.name "Your Name"

Set your global email address:

git config --global user.email "youremail@example.com"

Step 5: Verify Git Configuration

To check that your Git configuration has been saved correctly, run:

git config --list

You should see your username and email listed in the output.

Step 6: Create and Initialize a Git Repository (Test)

To ensure everything works properly, create a test directory and initialize a Git repository:

mkdir git-test
cd git-test
git init

If successful, Git will create a .git directory and display a confirmation message.

Conclusion

You have successfully learned how to install and set up Git on Ubuntu Linux. Git is a powerful tool for source code management and collaboration, and mastering its basics is essential for any developer.

Related Articles