Installing Git on a shared hosting account is simple, the installation is fast and like most things Git, it just works.
This is a basic install without documentation. My main goal is to be able to push changes from remote repositories into the hosted repository, which also serves as the source directory of the live website. Like this.
The only two things you absolutely must have are shell access to the account and permission to use GCC on the server. Check both with the following command:
$ ssh joe@webserver 'gcc --version' gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50) [...]
If GCC replies with a version number, you should be able to install Git. SSH into your server and let’s get started!
If you see something like /usr/bin/gcc: Permission denied you don’t have access to the GCC compiler and will not be able to build the Git binaries from source. Find another hosting company.
Update your $PATH
None of this will work if you don’t update the $PATH environment variable. In most cases, this is set in .bashrc. Using .bashrc instead of .bash_profile updates $PATH for interactive and non-interactive sessions–which is necessary for remote Git commands. Edit .bashrc and add the following line:
Be sure ‘~/bin’ is at the beginning since $PATH is searched from left to right; to execute local binaries first, their location has to appear first. Depending on your server’s configuration there could be a lot of other stuff in there, including duplicates.
Double-check this by sourcing the file and echoing $PATH:
$ source ~/.bashrc $ echo $PATH /home/joe/bin:/usr/local/bin:/bin:/usr/bin
Verify that the remote path was updated by sending a remote command like this (from another connection):
$ ssh joe@webserver 'echo $PATH' /home/joe/bin:/usr/local/bin:/bin:/usr/bin
Note: Previous iterations of this page installed into the ~/opt directory. Following current Git conventions, I’m now installing into the default
SSH into your webserver. I created a source directory to hold the files and make cleanup easier:
$ cd $ mkdir src $ cd src
Grab the most recent source tarball from Github. When this post was updated, the current Git release was version 18.104.22.168:
$ curl -LO https://github.com/git/git/tarball/v22.214.171.124
Untar the archive and cd into the new directory:
$ tar -xzvf v126.96.36.199 $ cd git-git-9dfad1a
By default, Git installs into
~/bin which is perfect for shared hosting. Earlier versions required adding a prefix to the configure script (like this), but none of that is necessary anymore. If you do need to change the install location of Git, just specify a prefix to the Make command as described in Git’s INSTALL file.
With all that taken care of, installation is simple:
$ make $ make install [lots of words...]
That should be it, check your installed version like this:
$ git --version git version 188.8.131.52
It's now safe to delete the src folder containing the downloaded tarball and source files.