Using a newer version of Git
Learn how to configure and use a newer version of Git on your account or server.
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.
Note
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 an 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:
-
Log in to your account using SSH.
-
At the command prompt, type the following commands:
echo 'alias git="/usr/local/cpanel/3rdparty/bin/git"' > ~/.bashrc source ~/.bashrc
-
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.
Important
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:
-
Log in to your account using SSH.
-
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
-
To configure your shell environment to use the new compiled executable, type the following commands. Replace username with your own hosting.com account username:
echo 'alias git="/home/username/bin/git"' > ~/.bashrc source ~/.bashrc
-
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:
-
Log in to your server using SSH.
-
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 AlmaLinux, type:
yum install git gcc autoconf perl-devel gettext
-
-
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 AlmaLinux, type:
yum install epel-release yum install asciidoc xmlto docbook2X ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
-
-
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
Tip
By downloading the Git source code using the Git client itself, it is easy to download the latest source code whenever you want.
-
To compile the Git binaries, type the following command:
make all
Note
If you want to compile the Git documentation as well, type the following command instead:
make all doc info man
-
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 AlmaLinux, type:
yum remove git git-man
Note
Removing the version installed by the package manager helps prevent any conflicts with the Git version you compiled locally.
-
-
To install the compiled Git binaries, type the following command:
make install
Note
If you want to install the compiled Git documentation as well, type the following command instead:
make install doc info man
-
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.31.0).
More Information
For more information about Git, please visit https://git-scm.com.
Related Articles
Updated 3 days ago