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.

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.

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

export PATH=$HOME/bin:$PATH

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 ~/bin.

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 recent source tarball from Github. When this post was updated, the current Git release was version 1.7.10.1:

$ curl -LO https://github.com/git/git/tarball/v1.7.10.1

Untar the archive and cd into the new directory:

$ tar -xzvf v1.7.10.1
$ 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 1.7.10.1

It's now safe to delete the src folder containing the downloaded tarball and source files.

My preferred shared hosting providers are A2 Hosting and WebFaction.


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

      • eirik

        Holy shit. I can’t believe that actually worked! But it did!

        Thanks * 1000.

      • Keith David Bershatsky

        Thank you very much — greatly appreciated !!!

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

  • laxxy

    Looks like it has some dependencies that are not installed by default in my case:
    In file included from http.c:1:http.h:6:23: warning: curl/curl.h: No such file or directoryhttp.h:7:23: warning: curl/easy.h: No such file or directoryIn file included from http.c:1:http.h:46: error: expected specifier-qualifier-list before ‘CURLcode’http.h:51: error: expected specifier-qualifier-list before ‘CURL’

    (the “curl” command itself worked fine; this is me trying to install 1.7.10.2 on RHEL 6.2; same result with 1.7.10.1

  • mackk2

    Hi,
    I have this error when i attempt to grab the source from github : curl: (77) Problem with the SSL CA cert (path? access rights?)
    What I missed?

    Thanks

  • http://jplew.com/ JP Lew

    thanks Joe. easy peasy. Installed on the first try thanks to your great instructions.

  • http://twitter.com/theoploumis TheodorosPloumis

    Hi, thanks for this great tutorial.
    My shared host with FREEBSD provides GCC but not Python. So I had to install it manually.
    Then python is running from “~/opt/bin/python”.

    The problem is that when I run “$ make” to compile git there is an error saying:

    “/usr/local/bin/python: Command not found”

    That means that git looks for python on the default path.

    How can I change this default path permantly or even before compiling to avoid this error?

    Thanks a lot!

  • hilliuse

    I have git installed on a DreamHost shared but I wanna upgrade the install. Anyone know how I do that?

  • http://www.facebook.com/tinotriste Tino Triste

    Worked great!

  • Matt Hughes

    If you get “Error expanding embedded variable.”, try running `gmake` instead of `make`.

  • adamvert

    I tried to follow these (excellent) instructions on my shared host, but I was getting all kinds of errors about missing dependencies (openssl, curl, etc.). For anyone else with the same problem, you can switch off most of the dependencies like this:

    make -i NO_TCLTK=YesPlease NO_OPENSSL=YesPlease NO_CURL=YesPlease NO_EXPAT=YesPlease

  • http://www.facebook.com/people/Rob-Brooks/100002184533783 Rob Brooks

    Worked perfectly on Triple8Netorks hosting. Thanks!

  • http://bestwebhostingratings.com/hosting/bluehost-review/ terry smith

    Hey thanks for such nice explanation.I have solved all my problem!!!

  • Kevin

    keep getting stuff like “http.c:1438: error: âstruct http_object_requestâ has no member named âslotâ” when i try to make. Also, I don’t know what “Be sure ‘~/bin’ is at the beginning” means. The beginning of what, exactly?

  • Rahul Venkat

    Thanks a lot for the post. It worked like a charm!!

  • TweetsOfSumit

    I’m just too noob for this. You should mention putty. And here: “Edit .bashrc and add the following line:” – how to edit a file? I know i know i’m a noob but still… :-/