Introduction

Version control has become an indispensable tool in modern software development. Version control systems allow you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch off from the base code to create alternative versions of files and directories.

One of the most popular version control systems is git. Many projects maintain their files in a Git repository, and sites like GitHub and Bitbucket have made sharing and contributing to code with Git easier than ever.

In this guide, we will demonstrate how to install Git on a CentOS 7 server. We will cover how to install the software in a couple of different ways, each with their own benefits, along with how to set up Git so that you can begin collaborating right away.

 

Prerequisites

Before you begin with this guide, there are a few steps that need to be completed first.

You will need a CentOS 7 server installed and configured with a non-root user that has sudo privileges. If you haven't done this yet, you can run through steps 1-4 in the CentOS 7 initial server setup guide to create this account.

Once you have your non-root user, you can use it to SSH into your CentOS server and continue with the installation of Git.

 

Install Git

The two most common ways to install Git will be described in this section. Each option has their own advantages and disadvantages, and the choice you make will depend on your own needs. For example, users who want to maintain updates to the Git software will likely want to use yum to install Git, while users who need features presented by a specific version of Git will want to build that version from source.

Option One — Install Git with Yum

The easiest way to install Git and have it ready to use is to use CentOS's default repositories. This is the fastest method, but the Git version that is installed this way may be older than the newest version available. If you need the latest release, consider compiling git from source (the steps for this method can be found further down this tutorial).

Use yum, CentOS's native package manager, to search for and install the latest git package available in CentOS's repositories:

  1. sudo yum install git

If the command completes without error, you will have git downloaded and installed. To double-check that it is working correctly, try running Git's built-in version check:

  1. git --version

If that check produced a Git version number, then you can now move on to Setting up Git, found further down this article.

Option Two — Install Git from Source

If you want to download the latest release of Git available, or simply want more flexibility in the installation process, the best method for you is to compile the software from source. This takes longer, and will not be updated and maintained through the yum package manager, but it will allow you to download a newer version than what is available through the CentOS repositories, and will give you some control over the options that you can include.

Before you begin, you'll need to install the software that git depends on. These dependencies are all available in the default CentOS repositories, along with the tools that we need to build a binary from source:

  1. sudo yum groupinstall "Development Tools"
  2. sudo yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel

After you have installed the necessary dependencies, you can go ahead and look up the version of Git that you want by visiting the project's releases page on GitHub.

The version at the top of the list is the most recent release. If it does not have -rc (short for "Release Candidate") in the name, that means that it is a stable release and is safe for use. Click on the version you want to download to be taken to that version's release page. Then right-click on the Source code (tar.gz)button and copy the link to your clipboard.

Now we are going to use the wget command in our CentOS server to download the source archive from the link that we copied, renaming it to git.tar.gz in the process so that it is easier to work with.

Note: the URL that you copied may be different from mine, since the release that you download may be different.

  1. wget https://github.com/git/git/archive/v2.1.2.tar.gz -O git.tar.gz

Once the download is complete, we can unpack the source archive using tar. We'll need a few extra flags to make sure that the unpacking is done correctly: z decompresses the archive (since all .gz files are compressed), x extracts the individual files and folders from the archive, and f tells tar that we are declaring a filename to work with.

  1. tar -zxf git.tar.gz

This will unpack the compressed source to a folder named after the version of Git that we downloaded (in this example, the version is 2.1.2, so the folder is named git-2.1.2). We'll need to move to that folder to begin configuring our build. Instead of bothering with the full version name in the folder, we can use a wildcard (*) to save us some trouble in moving to that folder.

  1. cd git-*

Once we are in the source folder, we can begin the source build process. This starts with some pre-build checks for things like software dependencies and hardware configurations. We can check for everything that we need with the configure script that is generated by make configure. This script will also use a --prefix to declare /usr/local (the default program folder for Linux platforms) as the appropriate destination for the new binary, and will create a Makefile to be used in the following step.

  1. make configure
  2. ./configure --prefix=/usr/local

Makefiles are scriptable configuration files that are processed by the make utility. Our Makefile will tell makehow to compile a program and link it to our CentOS installation so that we can execute the program properly. With a Makefile in place, we can now execute make install (with sudo privileges) to compile the source code into a working program and install it to our server:

  1. sudo make install

Git should now be built and installed on your CentOS 7 server. To double-check that it is working correctly, try running Git's built-in version check:

  1. git --version

If that check produced a Git version number, then you can now move on to Setting up Git below.

 

Set Up Git

Now that you have git installed, you will need to submit some information about yourself so that commit messages will be generated with the correct information attached. To do this, use the git configcommand to provide the name and email address that you would like to have embedded into your commits:

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

To confirm that these configurations were added successfully, we can see all of the configuration items that have been set by typing:

  1. git config --list
  1. user.name=Your Name
  2. user.email=you@example.com

This configuration will save you the trouble of seeing an error message and having to revise commits after you submit them.

How To Install Git on CentOS 7的更多相关文章

  1. Install latest git on CentOS 6/7

    Assuming you have sudo/root permission. Try rpmforge-extras first. yum --disablerepo=base,updates -- ...

  2. Install ssdb-rocks on CentOS 6

    Install ssdb-rocks on CentOS 6 C.C.  发表于 2014年08月10日 20:14 | Hits: 649 为了优化节操精选的弹幕系统,打算更换到Facebook的R ...

  3. how to install git 1.8 rpm

    git版本在低于1.8之前,对于私有项目会出现401的pull失败错误,只能通过升级git版本来解决 It appears that git18 is no longer available from ...

  4. git的CentOS服务端安装和windows客户端的使用

    git的CentOS服务端安装和windows客户端的使用 此教程以 搬瓦工vps CentOS 6 x64 的系统为环境,搭建 git 服务端.windows 7 系统为客户端. git客户端 在W ...

  5. How To Install Java on CentOS and Fedora

    PostedDecember 4, 2014 453.8kviews JAVA CENTOS FEDORA   Introduction This tutorial will show you how ...

  6. Install Redis on CentOS 6.4--转

    Install Redis on CentOS 6.4 source:http://thoughts.z-dev.org/2013/05/27/install-redis-on-centos-6-4/ ...

  7. Steps to Install Hadoop on CentOS/RHEL 6---reference

    http://tecadmin.net/steps-to-install-hadoop-on-centosrhel-6/# The Apache Hadoop software library is ...

  8. How to install MP4box on CentOS 6

    How to install MP4box on CentOS 6 MP4Box is a MP4 multiplexer. It can import MPEG-4 video, DivX, Xvi ...

  9. cygwin install git

    Installation with Cygwin If you're comfortable with Cygwin, then use it to install git, ssh, wget an ...

随机推荐

  1. 使用Jenkins自动编译我的 java 项目 git maven jenkins

    之前的项目已经将jenkins部署好,现在添加maven项目 准备工作 安装插件 Git plugin Publish Over SSH 全局设置  key: 是 linux服务器的私钥 Global ...

  2. LeetCode OJ:Insertion Sort List (插入排序链表)

    Sort a linked list using insertion sort. 用插入排序来排序一个list,额, 我写的好麻烦啊, debug了好久,至少提交了5次...写吐了快,先贴代码,写的也 ...

  3. LeetCode OJ :Remove Linked List Elements (移除链表元素)

    Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...

  4. Android中Application是什么?

    Application是什么? Application和Activity,Service一样,是android框架的一个系统组件,当android程序启动时系统会创建一个 application对象, ...

  5. php之接口内curl请求其他接口

    今天遇到一个需要写curl的需求,情况是这样的: 同一应用的A系统(购物系统),B系统(答题系统)相互独立,用户数据全部存在于A系统的数据库中, 现在处于B系统的某项操作中,需要在B系统中验证当前请求 ...

  6. 9.详解引擎(InnoDB,MyISAM)的内存优化攻略?

    整理自互联网!! 本篇我们讲解内存优化. 注意:以下都是在MySQL目录下的my.ini文件中改写. 一.InnoDB内存优化 InnoDB用一块内存区域做I/O缓存池,该缓存池不仅用来缓存InnoD ...

  7. 从无到有开发自己的Wordpress博客主题---创建主题

    上一篇教程,我们已经安装了Wordpress,我们可以成功的登录到Wordpress后台,接下来的任务就是创建我们自己的主题. 要想创建一个Wordpress主题,就必须按照Wordpress的规则, ...

  8. mac/linux ssh 免密码登陆配置及错误处理

    先说一下,mac 和linux 的设置方法是一样的 一般做法可以参照http://www.tuicool.com/articles/i6nyei 第一步:生成密钥.在终端下执行命令: ssh-kege ...

  9. 人生苦短之我用Python篇(深浅拷贝、常用模块、内置函数)

    深浅拷贝 有时候,尤其是当你在处理可变对象时,你可能想要复制一个对象,然后对其做出一些改变而不希望影响原来的对象.这就是Python的copy所发挥作用的地方. 定义了当对你的类的实例调用copy.c ...

  10. InnoSetup使用笔记

    今天用InnoSetup做安装包时,因为要装的驱动区分32位.64位,64位系统中要安装32位+64位驱动. 想在脚本中进行判断.折腾一阵,终于搞定: 参考了:http://379910987.blo ...