views:

682

answers:

2

Backstory

I'm on Rails 2.1 and need to freeze the Capistrano gem to my vendor folder (as my host has broken their cap gem dependencies and I want to make myself as independent as possible).

On my local windows machine I've put the following my environment.rb

config.gem "capistrano", :version => "2.5.2"
config.gem "net-ssh", :lib => "net/ssh", :version => "2.0.4"
config.gem "net-scp", :lib => "net/scp", :version => "1.0.1"
config.gem "net-sftp", :lib => "net/sftp", :version => "2.0.1"
config.gem "net-ssh-gateway", :lib => "net/ssh/gateway", :version => "1.0.0"

The gems were already installed and so I froze them. Checking ...

>rake gems
...
[F] capistrano = 2.5.2
[F] net-ssh = 2.0.4
[F] net-scp = 1.0.1
[F] net-sftp = 2.0.1
[F]net-ssh-gateway = 1.0.0

I then commit to SVN locally and update on the prod Linux box.

Problem

When I try and run my frozen version of Capistrano I get the following error.

$ ./vendor/gems/capistrano-2.5.2/bin/cap deploy-with-migrations 
./vendor/gems/capistrano-2.5.2/bin/cap:3:in `require': no such file to load --capistrano/cli (LoadError)
    from ./vendor/gems/capistrano-2.5.2/bin/cap:3

Any ideas what I've done wrong?

Update

See new related question

+2  A: 

You haven't done anything wrong. You're seeing this issue because the cap file under capistrano/bin/cap isn't meant to be run as a stand-alone. You'll see the same result if you try to run it from your primary gem folder. The cap executable (stored at /usr/bin/cap on a standard linux install) requires rubygems, registers capistrano and then loads the capistrano/bin/cap file.

One solution to this would be to add require 'rubygems' to your capistrano/bin/cap file:

#!/usr/bin/env ruby
require 'rubygems'
require 'capistrano/cli'
Capistrano::CLI.execute

If you don't want to modify capistrano/bin/cap you could specifically include the rubygems library when you run it using the -r flag. Your given command would look like this:

$ ruby -r rubygems ./vendor/gems/capistrano-2.5.2/bin/cap deploy-with-migrations
Gordon Wilson
Fantastic - thank you!
RichH
A: 

Another way to use a specific version of Capistrano would be something like, add an alias to your .bash_login like the following:

alias cap1='cap _1.4.2_ '

where cap1 is the command you will run and 1.4.2 is the version you want that command to run, then you can:

cap1 deploy

would then use that version of capistrano to deploy your application.

railsninja