Fixing “Gem bundler is not installed” when using Capistrano

Sometimes (just sometimes, otherwise it wouldn’t be Rails) you may get the following error when deploying an app with Capistrano:

 ERROR: Gem bundler is not installed, run `gem install bundler` first.

The problem is, you do have bundler installed, but even though it fails with cap. To solve this problem, run the following command in the server, with the user that Capistrano runs:

rvm wrapper `rvm current` bundle bundle

After that you should be fine. Thanks to Diego Plentz for the tip *cof* hack *cof*.