Even though the mentioned 3 tools are the de facto that everyone is using, it’s actually a huge pain in the ass to set up for the first time. One could easily spend a few days just trying to troubleshoot any problems that come up, and there are so many potential problems that even Google doesn’t have all the answers in plain sight.
First, install git and gitosis. I run debian so you’ll have to find the equivalent commands on your version of linux, but for debian/ubuntu you can install those using:
aptitude install git-core gitosis curl
For CentOS you can install git with yum using
yum install git-core
But for gitosis, you’ll have to install it via the python install or adding the REPOs referenced in this post.
Curl will be used to install RVM.
Now for RVM, run this command:
bash << (curl -s https://rvm.beginrescueend.com/install/rvm)
If you run that command as root, it will do a system install. Otherwise, it will do a user install (RVM will only work for that user). It's up to you which one you want to do, but I usually do a system install. After the install, you'll need to add this to /etc/profile or the .bash_profile of every user you want to use RVM:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
The above code is for a user install. If you're doing a system install, replace $HOME/.rvm/scripts/rvm with /usr/local/bin/rvm.
depending on where you added that code. Once it's installed, install your preferred version of ruby. I use REE, so I do
rvm install ree
Once you have your version of ruby running, you may want to create separate gemsets. If so, use this command:
rvm gemset create yourgemset
If you don't use a gemset, it will just use the default gemset which is no gemset. On your local machine, install capistrano with this command:
gem install capistrano
Go to the root of your rails application, and type:
This will generate a Capfile and, more importantly, a deploy.rb inside your config folder. This deploy.rb is the heart of how you will deploy applications now. I won't go into a sample cap file since there are quite a bit on the web, but I think it's good to mention that capistrano is just a tool that runs commands for you, instead of you having to go into the machine and do them yourself. You can create capistrano tasks which are just basically commands you'd type when you're SSHed into a machine, only here you can run them easily by doing cap namespace:task. That's all there is to it.
To get RVM and capistrano working, check out my earlier post about it.
Now, gitosis is kind of a bitch to work with if you haven’t used it before. I find this tutorial to be a very valuable resource when working with gitosis, especially the initial setup. However, one thing to add to that tutorial that YOU MUST DO is SSH into your REMOTE machine as the user that will be used to deploy the application. You must generate an SSH key for that user, and add it to the gitosis-admin keydir and basically add that user as a gitosis user in addition to yourself. This is needed since capistrano will use that user to deploy and get the code from gitosis.
After all this is working, you should have a basic setup with rvm + capistrano + gitosis working. It’s real tough to install the first time, but after a while you get used to it. If anyone finds anything to add to this tutorial, I’d be more than happy to update this post!