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.
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
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.
Holy shit. I can’t believe that actually worked! But it did!
Thanks * 1000.
Thank you very much — greatly appreciated !!!
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.
Thanks, Joe. You da man!
Just wanted to say thanks for this!
Thanks, great post. Worked perfectly and is one more port in navigating the sea of information regarding git.
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.
Thank you so much. This worked perfectly!
Great post I hope that this works on my shared linux hosting package.
Up and running in 2mins on Centos. Brilliant post, thanks
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.
I’m guessing you need to start a new session, or source .bashrc to update your $PATH. Did it work on your next connection?
What can I do if I get this:
/usr/bin/gcc: Permission denied
Is it possible to work around this on remote host?
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.
Not really. You can first check with your hosting provider if they can allow you access to gcc. Mine did.
Not really. You can first check with your hosting provider if they can allow you access to gcc. Mine did.
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.
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.
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
I was having the same issue as Bryan, and this fixed it! Thank you so much!!!
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
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!
Great tutorial ~~
But I got the latest git from the official site. Currently its on 1.7.8.3.
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
i have same problem
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
Use -k flag. Like “curl -kOL http://github…”
thanks Joe. easy peasy. Installed on the first try thanks to your great instructions.
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!
I have git installed on a DreamHost shared but I wanna upgrade the install. Anyone know how I do that?
Worked great!
If you get “Error expanding embedded variable.”, try running `gmake` instead of `make`.
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
I had to use the same set of switches with ‘make install’ too.
Worked perfectly on Triple8Netorks hosting. Thanks!
Hey thanks for such nice explanation.I have solved all my problem!!!
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?
Thanks a lot for the post. It worked like a charm!!
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… :-/
I’d like to add my two cents by highlighting this line: “Using .bashrc instead of .bash_profile updates $PATH for interactive and non-interactive sessions–which is necessary for remote Git commands.”
Do pay attention to that – it could save you a lot of time.
here is a good response if someone can’t understand how to create .bashrc
http://stackoverflow.com/a/20384224/4594690
Thank you, this was perfect!
I’m trying to execute “ssh myhost@myhost ‘gcc –version'” and get back ‘host key verification failed’
What should I do?
По русски тоже можно ответить)
http.h:6:23 warning: curl/curl.h: No such file or directory
can you help me with this?
It might be too late but hope to help.
Just download the curl tar and set its path for git configure, ie:
cd ~/
mkdir src
cd src
wget https://github.com/git/git/archive/v2.7.1.tar.gz
wget https://curl.haxx.se/download/curl-7.47.1.tar.gz
tar -xzvf v2.7.1.tar.gz
tar -xzvf curl-7.47.1.tar.gz
cd git-2.7.1/
make configure
./configure –prefix=$HOME –with-curl=~/src/curl-7.47.1
make
make install
i get this… make: *** [po/build/locale/bg/LC_MESSAGES/git.mo] Error 127
any ideas?
Any errors above that message?
Maybe missed gettext, FYI –
http://stackoverflow.com/questions/9500898/compiler-error-msgfmt-command-not-found-when-compiling-git-on-a-shared-hosting
Luan, Thanks a lot, your post was helpful !!
Luan, your answer helped me a lot! This solution solved my problem. Thanks!
Late to the party but this worked for me! I also had to add the -i flag to my make install to get it to work, however
Thanks for these great instructions! Only thing you might add for newbies is how to access .bashrc and edit it (ie. nano). Also perhaps how to remove directories. Us Windows users have to look this stuff up. Thanks again.
Old post but great — unfortunately i’m stuck at “Verify that the remote path was updated by sending a remote command like this (from another connection):”
i get the expected output when logged in to the remote host. but when i send the remote command i get “/usr/local/sbin…” back as opposed to “/home/ctwellma/bin” Thoughts?
make command is not found, what do I do?
Is there any instructions for installing Grav without shell access? The people that will end running this if we decide to use it barely know how to turn on their computer and I won’t be around to administer.
Thank you, thank you, thank you! Worked a treat on CentOS.