Joe Maller.com

How to install Git on a shared host

(regularly updated)

Installing Git on a shared hosting account is simple, the installation is fast and like most things Git, it just works.

As with my previous Subversion on shared hosting post, this will be a barebones install. 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) 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 won’t 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:

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

Note: Installing into the ~/opt directory 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 and make 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.6:

$ curl -LO http://kernel.org/pub/software/scm/git/git-1.7.6.tar.bz2

Untar the archive and cd into the new directory:

$ tar -xjvf git-1.7.6.tar.bz2
$ cd git-1.7.6

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.6

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.

My preferred shared hosting providers are A2 Hosting and WebFaction.

No related posts.


  • http://www.babbledog.com Gregg Lind

    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.

  • http://writeonly.wordpress.com Gregg Lind

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

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

  • draco

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

  • http://www.joemaller.com Joe

    @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.

  • http://webevelopment2.com Kevin Lloyd

    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.

  • neochap

    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..

  • Erwin

    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

    • Jacksmirk

      I had this problem too. You can install git by installing in your local machine the linux distribution that your server is using (centOS 5.7 in my case) and install there git into a single folder. Then you pack the folder into a tar.gz, upload to your home directory in the server and untar. Finally you have to create the PATH in the .bashrc file.

  • http://eapen.in Eapen

    Worked like a charm, thanks much!

  • http://entropycreations.com evgeny

    thank you for this post i was missing

    ./configure –prefix=$HOME

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

  • http://pfcstudio.net Paul

    Many thanks for this nice post.

  • http://drupalsteve.com steve oliver

    Thanks, Joe. You da man!

  • http://www.perceptum.biz/ Bryan Gruneberg

    Just wanted to say thanks for this!

  • Andre

    Thanks, great post. Worked perfectly and is one more port in navigating the sea of information regarding git.

  • Bfritton

    Thank you so much! I was getting a ton of permission denied errors from another tutorial because of an incorrectly configured path. This fixed it all.

  • Eric Famiglietti

    Thank you so much.  This worked perfectly!

  • http://www.webelity.com/product/drupal-web-developers Drupal Web Developers

    Great post I hope that this works on my shared linux hosting package.

  • Si77hayward

    Up and running in 2mins on Centos.  Brilliant post, thanks

  • dotandpixel

    Thanks for this tutorial. Worked perfectly – except for the last step

    git –version
    - bash: git: command not found

    any ideas? every other step had the same results as the tutorial.

    • http://joemaller.com Joe Maller

      I’m guessing you need to start a new session, or source .bashrc to update your $PATH. Did it work on your next connection?

  • kristin.e

    What can I do if I get this:

    /usr/bin/gcc: Permission denied

    Is it possible to work around this on remote host?

    • http://joemaller.com Joe Maller

      The only workaround is to switch hosting providers. Your account doesn’t have access to the GCC compiler, so you can’t build the Git binaries from source.

      I updated the prerequisites section to explain this a little better.

      • http://www.vipreads.com Siddharth Sarda

        Not really. You can first check with your hosting provider if they can allow you access to gcc. Mine did.

    • http://www.vipreads.com Siddharth Sarda

      Not really. You can first check with your hosting provider if they can allow you access to gcc. Mine did.

  • http://k4gdw.myopenid.com/ Bryan

    I know this is a fairly old thread, but here goes. I’m connecting to a friend of mine’s box via SSH (no root access and he’s hard to get in touch with to get him to do this for me).  Everything was working great up to the first make command, at which time I get this message:

    [grndrgn@rtfm git-1.7.7.1]$ make
        CC daemon.o
    In file included from daemon.c:1:
    cache.h:19:18: error: zlib.h: No such file or directory
    In file included from daemon.c:1:
    cache.h:21: error: expected specifier-qualifier-list before âz_streamâ
    make: *** [daemon.o] Error 1
    [grndrgn@rtfm git-1.7.7.1]$

    Any ideas?  One of the lines indicates that it can’t find zlib.h.  So I installed a local user copy of zlib.  However, I can’t figure out how to tell git’s make program where to find it.

    • http://joemaller.com Joe Maller

      Poke around in the configure file, there are options for specifying alternate file locations for the compiler. Take a look at my linked post about installing Subversion. That was really difficult and I ended up specifying alternate locations for several libraries. 

      Or you could try compiling Git binaries on a similar machine and then uploading those.

    • Guest

      You need to compile zlib the same way (configure –prefix=$HOME/opt) and provided zlib’s location to git via
      ./configure –prefix=$HOME/opt –with-zlib=$HOME/opt

      • Josiah

        I was having the same issue as Bryan, and this fixed it!  Thank you so much!!!

  • Phil

    After a bit of messing around, here’s how to install the man pages assuming your install prefix was $HOME/opt as above (substitute your version number as appropriate below):

    cd $HOME/opt/share/man/

    curl -LO “http://git-core.googlecode.com/files/git-manpages-1.7.7.4.tar.gz

    tar xvfz git-manpages-1.7.7.4.tar.gz

    You should now have man1, man5 and man7 directories in $HOME/opt/share/man

    The last step is to make sure man finds them (add this to .bashrc):

    export MANPATH=$HOME/opt/share/man:$MANPATH

  • http://firemouse.myopenid.com/ FireMouse

    I learned so much just from this one brief tutorial!
    I’ve never permanently added to the $PATH environment using .bashrc before, and never brought in source and ran a “make” with a compiler before – and never added man pages before. . .
    Of course, you have to already know your way around a little bit to handle this, But far too many tutorials are sloppy, inaccurate, and obfuscated with too much unnecessary “fluff”. 

    Thank you Joe for your excellent, concise and to the point tutorial! 

  • Anonymous

    Great tutorial ~~
    But I got the latest git from the official site. Currently its on 1.7.8.3.