Joe Maller.com

How to install Git on a shared host

(regularly updated)

I got a lot of really positive feedback for my installing Subversion on a shared host piece, but now that I’ve mostly switched over to Git, I figured I might as well write a companion post.

These instructions are much simpler, the installation is fast, and, like most things Git, it just works.

As with my previous Subversion solution, this will be a barebones install. It’s almost certainly against the terms of your hosting plan to run any daemons. The purpose of this installation is to be able to push changes from remote repositories into the hosted repo, where the hosted repository may also serve as the source directory of the live website. Like this.

Prerequisites

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) 3.4.6 20060404 (Red Hat 3.4.6-11)
[...]

If GCC replies with a version number, you should be able to install Git.

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:

export PATH=$HOME/opt/bin:$PATH

Be sure ‘~/opt/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 ~/.bash_profile
$ echo $PATH
/home/joe/opt/bin:/usr/local/bin:/bin:/usr/bin

Double-check that the remote path was updated by sending a remote command like this:

$ ssh joe@webserver 'echo $PATH'
/home/joe/opt/bin:/usr/local/bin:/bin:/usr/bin

Note: I updated this post and am now installing to the ~/opt directory. This keeps the home folder cleaner and is where add-on applications are customarily installed on Unix systems.

Installing Git

SSH into your webserver. I created a source directory to hold the files which made cleanup easier:

$ cd
$ mkdir src
$ cd src

Grab the most current source tarballs from the Git site. At the time this post was last updated, the most recent version was v1.7.1:

$ curl -LO http://kernel.org/pub/software/scm/git/git-1.7.1.tar.gz

Untar the archive and cd into the new directory:

$ tar -xzvf git-1.7.1.tar.gz
$ cd git-1.7.1

This next step is the only one that really seems to matter with regards to shared hosting. The Configure script needs to be told where to install, and because we’re on a shared host, Git’s files should be put somewhere in our home directory:

$ ./configure --prefix=$HOME/opt
[words...]

Lastly, make and install:

$ make && make install
[lots of words...]

That should be it, check your installed version like this:

$ git --version
git version 1.7.1

It's now safe to delete the src folder which contained the download and source files.

Note that these instructions do not install Git's documentation man pages. Also, these instructions appear to work exactly the same on Mac OS X, though the installer package is way easier and includes documentation.


10 Responses to “How to install Git on a shared host”

  • Hi Joe,

    Saw your twitters:

    joemaller what are the workarounds for svn’s “Item already exists in filesystem” error message with git-svn dcommit? #git
    joemaller git-svn dcommit is ruining my morning.

    git-svn routinely ruins mine :) It mostly works, but when it doesn’t, boy oh boy!

    The specific answer:

    Go to your svn, and svn up. Then try rebasing / dcommitting.

    General strategy for git-svn. Do everything in git unless absolutely necessary.

  • My answer was dumb…. this one is much better:

    http://www.jukie.net/~bart/blog/20080916155113

  • Does one need root access to install git as described in your article? Or simply a shared host with SSH access?

  • @draco you’re never going to have root access on a shared account. Installing to your user home folder on the webserver should work everywhere, so long as the standard unix compilers are available.

  • Many, many thanx for this tutorial.

    I use Github for some personal stuff, but when I work on client code, it would be lovely if I had a remote repo to upload to.

    I can’t thank you enough.

  • Hi Draco,

    When I run the command ./configure –prefix=$HOME

    I get permission denied error.

    Do I have to change $HOME with the directory name or something?

    I am new to Linux and shell.. Please help..

  • Hi, I’m trying to follow your path.
    Unfortunately gcc does not seem to be accessible for me as an ordinary user:
    - configure: error: no acceptable C compiler found in $PATH
    - gcc -version
    jailshell: /usr/bin/gcc: Permission denied

    Is there any solution to this situation?
    Can I install gcc in my homedir?

    Thanks for replying, and thanks for the HOWTO!

    Erwin

  • Worked like a charm, thanks much!

  • thank you for this post i was missing

    ./configure –prefix=$HOME

    and was getting errors, thanks to your article, i
    installed it finally ;)

  • Many thanks for this nice post.

Leave a Reply