How to Install Git on Linux Mint 22, 21 or 20

Git is a powerful and widely-used distributed version control system that allows developers to track changes in their code, collaborate with others, and manage project versions efficiently. It supports branching and merging, enabling multiple workflows and seamless collaboration among team members. Git also includes features such as lightweight local branching, convenient staging areas, and multiple workflows, making it an essential tool for modern software development. Its robust performance, scalability, and support for various development models make it suitable for projects of all sizes.

To install Git on Linux Mint 22, 21, or 20, you have several options. You can use the APT package manager with Linux Mint’s default repository for the most stable and secure method. For those needing the latest features, the Ubuntu Git Maintainers PPA is available. Additionally, this guide will cover how to download the latest Git archive, compile, build, and install it from the source.

Update Linux Mint Before GIT Installation

Before starting the installation process, it’s essential to update your Linux Mint system to ensure all packages are current and avoid any conflicts during the installation.

Run the following command to update the package lists:

sudo apt update

Upgrade any outdated packages by running the following:

sudo apt upgrade

Method 1: Select APT Method for Git Installation

Option 1: Install Git with the Default Linux Mint Repository

The easiest way to install Git is using the default repository provided by Linux Mint. This method is recommended for most users.

Check if Git is already installed by running the following:

git --version

If no output is returned, proceed to the next step.

Install Git using the following command:

sudo apt install git

Verify the installation by checking the Git version:

git --version

Option 2: Install Git from Ubuntu Git Maintainers PPA

For users who prefer the latest stable version of Git, the Ubuntu Git Maintainers PPA can be used. Linux Mint is based on the LTS version of Ubuntu, ensuring compatibility with your system.

Option 1: Import Ubuntu Git Maintainers PPA – Stable Branch

Add the stable branch of the Ubuntu Git Maintainers PPA by running:

sudo add-apt-repository ppa:git-core/ppa -y

Option 2: Import Ubuntu Git Maintainers PPA – RC Branch

Alternatively, you can add the release candidate branch, which might contain a more recent version of Git. We recommend the stable branch for most users, but you can add both PPAs if desired.

Add the release candidate branch by running:

sudo add-apt-repository ppa:git-core/candidate -y

After importing the desired repository, proceed with the following steps:

Update the package lists with the new PPA:

sudo apt update

Check the available Git versions using the policy command:

apt-cache policy git

This command will show the available Git versions from the different repositories. For now, don’t worry about the specific version numbers.

Now install Git using the following command:

sudo apt install git -y

This command works for both users with and without Git installed.

Verify the installation by checking the Git version:

git --version

Method 2: Install GIT via source Archive

This section will guide you through installing Git by compiling it from the source. This method might be preferred by users who want more control over the installation process or need specific features that may not be available in the packaged versions.

Install GIT Build Dependencies

Before compiling Git, you need to install the necessary build dependencies. Run the following command to install them:

sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip -y

Download Git Source Code

Visit the Git release page for the latest stable release or the master zip archive, then use the wget command to download the desired archive. Replace {version} with the version number you want to download:

wget https://github.com/git/git/archive/refs/tags/{version}.zip

Alternatively, you can download the latest development version (master) with the following command:

wget  https://github.com/git/git/archive/refs/heads/master.zip -O git.zip

Note: The master version may be unstable and contain bugs. For a more straightforward installation process, we recommend the stable release or the PPA method.

Extract and Compile Git Source Code

Start by extracting the downloaded archive using the unzip command. Make sure to replace {version} with the actual version number you downloaded:

sudo unzip {version}

After executing this command, you will have the extracted Git source code in a new directory.

Now, navigate to the extracted directory using the cd command. This will change the current working directory to the Git source code folder:

cd git-{version}

In this step, you will compile and install Git using two separate make commands. The first make command is responsible for compiling the source code with the specified prefix, ensuring that all necessary files are generated:

sudo make prefix=/usr/local all

By specifying the prefix as /usr/local, you are telling the build system to install Git into the /usr/local directory once the compilation is complete. The all option ensures that all components are built.

After completing the compilation, you will proceed to the installation stage. Run the following command to install Git:

sudo make prefix=/usr/local install

This command will install Git into the /usr/local directory, as specified by the prefix option. The installation process will copy the necessary files and set up the correct permissions, allowing you to use Git on your system.

Verify the installation and build once you have installed Git from the source.

git --version

Additional Commands & Tips for GIT

Update GIT

Since you installed Git using the APT package manager, updates to Git will be included with your standard system packages. To update and upgrade Git, run the following:

sudo apt update && sudo apt upgrade

Remove GIT

If you no longer want Git installed on your system, follow these steps to remove the software:

For users who installed Git using the APT package manager, run the following command:

sudo apt remove git

For users who installed Git from the PPA, use the following commands to remove it:

sudo add-apt-repository --remove ppa:git-core/ppa -y
sudo add-apt-repository --remove ppa:git-core/candidate -y

Conclusion

With Git successfully installed on your Linux Mint system, you can leverage its advanced version control features, such as branching and merging, staging areas, and various workflows. Whether you choose the stability of the default repository, the latest features from the Ubuntu Git Maintainers PPA, or the flexibility of building from source, each method ensures reliable code management. Regularly update your Git installation to maintain security and access to the latest features. Enjoy the enhanced collaboration and version control capabilities that Git brings to your development projects.

Categories Git

Leave a Comment