# Using a newer version of Git

> Use a newer version of Git than the one installed, either cPanel's alternate Git or one you compile from source.

Source: https://helpcenter.ruachost.com/developers/version-control/using-a-newer-version-of-git/

Learn how to configure and use a newer version of Git on your account or server. This may be necessary if:

- Your account on a managed server requires a Git version newer than what is installed.
- You have an unmanaged server and your Linux distribution's package repositories contain an outdated Git version.

### Configuring Managed Servers

If a managed server has an outdated Git client, you can use one of these methods:

#### Method 1: Use an Alternate Git Version

cPanel includes a newer Git client for its own updates. To use it:

1. Log in to your account using SSH.
2. Run the following commands:

```
echo 'alias git="/usr/local/cpanel/3rdparty/bin/git"' > ~/.bashrc
source ~/.bashrc
```

3. Confirm the Git version:

```
git --version
```

#### Method 2: Compile Git from Source

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

**Important:** This method is not officially supported on managed servers. Only the Git client is compiled; documentation requires additional packages not installed on managed servers.

1. Log in to your account using SSH.
2. Run 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. Configure your shell environment to use the new executable (replace `username` with your account username):

```
echo 'alias git="/home/username/bin/git"' > ~/.bashrc
source ~/.bashrc
```

4. Verify the new Git version:

```
git --version
```

### Configuring Unmanaged Servers

If your Linux distribution's package repositories contain an outdated Git version, you can compile the latest version from source.

1. Log in to your server using SSH.
2. Install compilation prerequisites as root:

**Ubuntu 14.04:**

```
apt-get install git gcc autoconf zlib1g-dev
```

**AlmaLinux:**

```
yum install git gcc autoconf perl-devel gettext
```

3. (Optional) Install packages for building Git documentation:

**Ubuntu 14.04:**

```
apt-get install asciidoc docbook2x
```

**AlmaLinux:**

```
yum install epel-release
yum install asciidoc xmlto docbook2X
ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
```

4. Download the Git source and configure the build environment:

```
git clone git://git.kernel.org/pub/scm/git/git.git
cd git
make configure
./configure
```

5. Compile the Git binaries:

```
make all
```

- To compile the binaries **and documentation**, run:

```
make all doc info man
```

6. Remove the Git version installed by the package manager to prevent conflicts:

**Ubuntu 14.04:**

```
apt-get purge git git-man
```

**AlmaLinux:**

```
yum remove git git-man
```

7. Install the compiled Git binaries:

```
make install
```

- To install **with documentation**, run:

```
make install doc info man
```

8. Log out and back in, then check the version:

```
git --version
```

The latest Git version should display (currently 2.31.0).

### More Information

For more details about Git, visit [https://git-scm.com](https://git-scm.com/).
