How to Install GIT on Linux Mint 21 | 20


Linux Mint comes with the ability to install GIT directly from its default repositories. While this is preferred, there are multiple methods to install GIT for users seeking a newer version with bug fixes or performance improvements. The following tutorial will teach you how to install GIT in various ways on Linux Mint 21 based on Ubuntu 22.04 LTS Jammy Jellyfish or Linux Mint 20 based on Ubuntu 20.04 LTS Focal Fossa using CLI commands.

Recommended Steps Before Installation

First, update your system to ensure all existing packages are up to date.

Before you begin, run an update on your system to ensure all packages are up-to-date to avoid any conflicts during the installation.

sudo apt update

Optionally, you can list the updates for users who require review or are curious.

sudo apt --list upgradable

Proceed to upgrade any outdated packages using the following command.

sudo apt upgrade

#1st Method: Install GIT – Default Repository

The first method is to install Git directly from the default repository. This is the easiest solution and is recommended. First, ensure you have not installed Git by running the following command.

If nothing is returned, run the installation command.

sudo apt install git

And that is it; you can additionally check the Git version installed by running the following command.

git --version

Example output:

git version 2.34.1

#2nd Method: Install Git – Ubuntu Git Maintainers PPA

The second method is to install the latest from the Ubuntu Git Maintainers team for the latest stable version. Given Linux Mint is based on the LTS version of Ubuntu, the compatibility for your system will be fine. For most users, I believe this version of GIT can be more desirable to get bug fixes and newer features, you have to way up the option and the environment you are working in.

Import Ubuntu Git Maintainers PPA

First, install the following packages that are required. These are most likely installed but run the command to be safe.

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https -y

For users who have not previously imported a GPG key from the Ubuntu keyserver, the command line terminal will often have issues importing GPG keys from LaunchPAD PPAs because the directories are not created. This is an easy fix. Use the following command that will, in turn, generate the directories.

sudo gpg --list-keys

Example output:

gpg: directory '/root/.gnupg' created
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created

The next task is to import the GPG key needed.

sudo gpg --no-default-keyring --keyring /usr/share/keyrings/git-core-ppa.gpg --keyserver keyserver.ubuntu.com --recv-keys E1DD270288B4E6030699E45FA1715D88E1DF1F24 > /dev/null

Example output:

gpg: keybox '/usr/share/keyrings/git-core-ppa.gpg' created
gpg: key A1715D88E1DF1F24: public key "Launchpad PPA for Ubuntu Git Maintainers" imported
gpg: Total number processed: 1
gpg:               imported: 1

With the GPG key now imported, you can import the LaunchPAD PPA. Remember, match the command to the version of Ubuntu you are utilizing, or the installation will likely fail with errors.

Import GIT PPA for Linux Mint 21

echo 'deb [signed-by=/usr/share/keyrings/git-core-ppa.gpg] https://ppa.launchpadcontent.net/git-core/ppa/ubuntu jammy main' | sudo tee -a /etc/apt/sources.list.d/git-core-ppa.list

Import GIT PPA for Linux Mint 20

echo 'deb [signed-by=/usr/share/keyrings/git-core-ppa.gpg] https://ppa.launchpadcontent.net/git-core/ppa/ubuntu focal main' | sudo tee -a /etc/apt/sources.list.d/git-core-ppa.list

Alternative Branch Git Release Candidate (RC release)

Alternatively, you can instead import the release candidate branch. Currently, they contain the same build, but generally, you will find a newer version when ready in this PPA first. For most users, I recommend installing stable, but you can import both PPAs. Generally, the one with the latest version should always be installed first.

See also
How to Install Telegram on Linux Mint 21 or 20

Import GIT Release Candidate PPA for Linux Mint 21

echo 'deb [signed-by=/usr/share/keyrings/git-core-ppa.gpg] https://ppa.launchpadcontent.net/git-core/candidate/ubuntu/ jammy main' | sudo tee -a /etc/apt/sources.list.d/git-core-ppa.list

Import GIT Release Candidate PPA for Linux Mint 20

echo 'deb [signed-by=/usr/share/keyrings/git-core-ppa.gpg] https://ppa.launchpadcontent.net/git-core/candidate/ubuntu/ focal main' | sudo tee -a /etc/apt/sources.list.d/git-core-ppa.list

With the repository imported, run a quick update command.

sudo apt update

Further, verify the repositories using the policy command to see if the PPA repositories are present. Do not worry about version numbers for now.

apt-cache policy git

Example output:

Further, verify the repositories by using the policy command.

For users that have Git installed and users that do not, I would recommend using the installation command for both.

sudo apt install git -y

Once installed, verify the installation.

git --version

Example output:

git version 2.39.0

When I created this tutorial, the default version was 2.34.1. With the PPA version, you can see it is upgraded to 2.39.0, which is a decent jump.

The following method is manual, but for users just seeking the latest Git, I suggest using the PPA before the technique below.

#3rd Method: Install GIT – Manual Method

Begin with installing the Git build dependencies with the following command.

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

Once the dependencies are installed, visit the release page to find the master zip archive or the latest stable release from Git.

Use the wget command to download the archive as below.

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

Use the wget command to get the latest development version (master).

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

Note, do not use this version unless it is unstable and possibly contains bugs, and you will need to update it more often. As I said a few times, using the PPA is much simpler.

Next, Unzip which archive you downloaded.

Example:

sudo unzip {version}

Now you will need to navigate to the directory using the CD command.

cd git-{version}

You now need to run the following make commands to install Git.

First command:

sudo make prefix=/usr/local all

Second command:

sudo make prefix=/usr/local install

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

git -version

GIT Example Commands & Configurations

The following parts will cover some typical setups and commands used daily by users of GIT.

GIT Add user

After installation, you must set up standard settings such as names and e-mails, mainly around git commit messages. This is pretty straightforward, as the tutorial will explain below.

The first step is to provide your name that will be set Globally.

git config --global user.name "YOUR NAME"

Next, select your e-mail; this can be fake if you prefer.

git config --global user.email "YOUR EMAIL"

GIT Create Directory

First, create a directory for users who want to make a new directory strictly for GIT.

mkdir example-directory -p

Next, navigate to the directory.

cd example-directory -p

The next task is to use the initialization command, creating a hidden .git directory to store the configuration, history, and so on.

git init

You will see a terminal output stating the status of the directory being initialized, and you can additionally see the content using the following command.

ls -a .git

Print GIT CONFIG Details

To confirm GIT config users and details, use the config –list command

git config --list

Unless specified, Git stores details in the ~/.gitconfig file. You can review what is currently stored by using the cat command.

cat ~/.gitconfig

The sudo command with the git config command will set two separate user names and e-mails.

See also
How to Install FileZilla Fedora Linux

Store GIT Credentials

For users who want to keep authorization details stored, you can enable the credential helper cache using the following.

git config --global credential.helper cache

If you must use credential helper, it is advised to cache only for a limited time for increased security. For example, if you will be working today using GIT for 1 to 4 hours but will not touch Git for maybe a few weeks, then set the expiry for 5 hours for best security practices.

git config --global credential.helper "cache --timeout=18000"

After 5 hours, the credentials will be deleted, securing your GIT.

Check Directory GIT Status

To view the status of a GIT repository, you can use the following git status command.

git status

While the above command helps with giving a status of the GIT, you can additionally list all git commands and sub.

Connect Remote GIT Repository

For users that need to work with GIT remotes to sync and download/upload changes, you will need to link the GIT. This can be done using the git remote command as follows.

git remote add origin remote-repository-link

Commit GIT Changes

When you have completed changes in your GIT directory and want to SYNC it to push to the remote repository, use the following git commit command.

git commit -m "git message changelog"

Note the -m “git message change” is the message that appears in the changelog.

Push GIT Changes

To push or send changes to the remote repository to SYNC in both versions, use the following git push command.

git push origin master

Pull GIT Changes

Alternatively, to pull or get changes from the remote repository to SYNC in both versions, use the following git push command.

git pull origin master

Additional Commands & Tips

How to Update GIT

For updates to GIT, they will be included with your standard system packages as you installed git-core with the APT package manager. Use the following command to update and upgrade.

sudo apt update && sudo apt upgrade

How to Remove (Uninstall) Git

For users that no longer want GIT installed, use the following command to remove the software.

sudo apt autoremove git -y

Users that installed Git from the PPA use the following command to remove it.

sudo rm /etc/apt/sources.list.d/git-core-ppa.list

Comments and Conclusion

Installing Git on Linux Mint is easy and can be done in three ways. The tutorial successfully shows you three different methods to install Git on Linux Mint. With these methods, you should have no problem installing Git on your system.

Leave a Comment

Index
Share to...