How to configure and use a newer version of Git

This article describes how to configure and use a newer Git version. You may want to do this if:

  • You have an account on a managed server, and you need a version of Git newer than what is installed on the server.
    This applies to all hosting accounts that have cPanel, including shared and reseller servers.
  • You have an unmanaged server, and the package repositories for your Linux distribution contain an outdated version of Git.

Configuring managed servers

Depending on the managed server where your account is located, there may be an outdated version of the Git client installed. If this is the case, there are two ways you can use a newer version of Git.

Method #1: Use alternate Git version

cPanel uses a newer version of the Git client for its own updates. To configure your account to use this version, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type the following commands:
    echo 'alias git="/usr/local/cpanel/3rdparty/bin/git"' >> ~/.bashrc
    source ~/.bashrc
    
  3. To confirm your account is configured to use the new version, type the following command:

    git --version
Method #2: Compile Git from source

If you need the latest version of Git, you can compile it from the source code.

Although we have tested and run this configuration, it is not supported. Additionally, you can only compile the Git client. Compiling the Git man pages and documentation requires packages that are not installed on managed servers.

To compile the Git client from source, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type the following commands:
    cd ~
    git clone git://git.kernel.org/pub/scm/git/git.git
    cd git
    make configure
    ./configure --prefix=$HOME
    make all
    make install
    
  3. To configure your shell environment to use the new compiled executable, type the following commands. Replace username with your own A2 Hosting account username:

    echo 'alias git="/home/username/bin/git"' >> ~/.bashrc
    source ~/.bashrc
    
  4. To confirm your account is configured to use the new version, type the following command:

    git --version

Configuring unmanaged servers

The package repositories for your Linux distribution may contain an outdated version of Git. To use the newest version of Git, you can build it from source. To do this, follow these steps:

  1. Log in to your server using SSH.
  2. As the root user, install the compilation prerequisites using the appropriate command for your Linux distribution:
    • For Ubuntu 14.04, type:
      apt-get install git gcc autoconf zlib1g-dev
      
    • For CentOS 7, type:

      yum install git gcc autoconf perl-devel gettext
      
  3. This step is optional. In addition to the Git binaries, you can compile and install the Git documentation. To install the prerequisites for building the documentation, use the appropriate command or commands for your Linux distribution:

    • For Ubuntu 14.04, type:
      apt-get install asciidoc docbook2x
      
    • For CentOS 7, type:

      yum install epel-release
      yum install asciidoc xmlto docbook2X
      ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
      
  4. To download the Git source code and configure the build environment, type the following commands:

    git clone git://git.kernel.org/pub/scm/git/git.git
    cd git
    make configure
    ./configure
    
    By downloading the Git source code using the Git client itself, it is easy to download the latest source code whenever you want.
  5. To compile the Git binaries, type the following command:

    make all 
    

    If you want to compile the Git documentation as well, type the following command instead:

    make all doc info man
    
  6. To remove the Git version that you installed using the package repositories in step 2, use the appropriate command for your Linux distribution:

    • For Ubuntu 14.04, type:
      apt-get purge git git-man
      
    • For CentOS 7, type:

      yum remove git git-man
      
    Removing the version installed by the package manager helps prevent any conflicts with the Git version you compiled locally.
  7. To install the compiled Git binaries, type the following command:

    make install 
    

    If you want to install the compiled Git documentation as well, type the following command instead:

    make install doc info man
    
  8. Log out of the server, and then log back in. At the command prompt, type the following command:

    git --version

    Git should display the latest version (at the time this article is written, the latest version is 2.7.0).

More Information

For more information about Git, please visit https://git-scm.com.

Get Git Hosting

Article Details

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.