CentOSLinuxTutorials

How To Install Git on CentOS 7

Install Git on CentOS 7

In this tutorial, we will show you how to install and configuration of Git on your CentOS 7. For those of you who didn’t know, Git a powerful and widely-used version control system, has become an essential tool for developers and system administrators alike. Its ability to efficiently manage code changes, collaborate with team members, and track project history has made it a staple in the world of software development. CentOS 7, a popular Linux distribution known for its stability and reliability, is often used in server environments.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Git on a CentOS 7 server.

Prerequisites

Before we dive into the installation process, ensure that your system meets the following requirements:

  • A server running one of the following operating systems: CentOS 7.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Git on CentOS 7

Step 1. To begin, it’s crucial to update your CentOS 7 system to the latest available packages. This step ensures that you have access to the most recent security patches, bug fixes, and compatibility improvements. To update your system, open a terminal and run the following command:

yum clean all
yum -y update

Step 2. Installing Git on CentOS 7.

  • Method 1 — Install Git with Yum

Run the following commands in for installation Git via yum:

yum install git

Once the installation is complete, you can verify the installed version of Git by running:

git --version

While installing Git from the default CentOS repositories is convenient, it’s important to note that the version provided may not always be the latest release. If you require the most recent version of Git or need access to specific features, you may want to consider installing Git from alternative sources.

  • Method 2 — Install Git from Source

Before installing Git from source code, make sure you have already installed the required packages on your system:

yum groupinstall "Development Tools"
yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel

Once the dependencies have been installed then we need to find out and download the latest version of Git software, At the moment of writing this article it is version 2.10.0:

wget https://github.com/git/git/archive/v2.26.2.tar.gz
tar xvf v2.26.2.tar.gz

After downloading and extracting the Git source code, Use the following command to compile the source code:

cd git*
make configure
./configure --prefix=/usr/local
make install

To check the current version of Git use the following command:

[root@idroot ~]# git --version
git version 2.26.2

Compiling Git from a source provides the most flexibility and control over the installation process. However, it requires more manual effort and may involve resolving dependencies if not already installed on your system.

Step 3. Configuring Git.

After installing Git, it’s important to configure it with your user information. This information is used to identify your commits and contributions. To configure Git, follow these steps:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Verify the configuration:

git config --list

Step 4. Basic Git Commands

Now that you have Git installed and configured, let’s explore some basic Git commands to get you started:

    • git init: Initializes a new Git repository in the current directory.
    • git clone: Creates a copy of an existing Git repository on your local machine.
    • git add: Stages changes for commit. Use git add . to stage all changes.
    • git commit: Records the staged changes as a new commit. Use git commit -m "Commit message" to include a descriptive message.
    • git push: Pushes your local commits to a remote repository.
    • git pull: Fetches changes from a remote repository and merges them into your local branch.

These commands form the foundation of working with Git. As you become more comfortable with Git, you’ll discover many more commands and options that enable powerful version control and collaboration workflows.

Congratulations! You have successfully installed Git. Thanks for using this tutorial for installing Git in CentOS 7 systems. For additional help or useful information, we recommend you check the official Git website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button