# Automating installation of gems on remote machine with Capis

**URL:** <https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426>\
**Category:** Ruby\
**Created:** [November 27, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426 "2006-11-27T22:58:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 27, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/1 "2006-11-27T22:58:57Z")

</div>

Greetings,

I’m wondering if anyone has used Capistrano to automate the installation  
of gems on remote machines.

The problem I’m having is that when you install a gem from the command  
line, at various stages it will prompt you for a ‘Y’ or ‘N’ answer.

Let’s say I have the following task and I want it to run on a remote  
machine:

desc “Install rails”  
task :install\_rails do  
run “gem install rails”  
end

The task starts up and begins the installation, but then hangs after I  
get the ‘Y’ or ‘N’ prompt.

Is there a way to just skip the prompt and specify ‘Y’ for everything?

Regards,  
Steven

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 27, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/2 "2006-11-27T23:00:59Z")

</div>

On 11/27/06, Steven H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The task starts up and begins the installation, but then hangs after I  
> get the ‘Y’ or ‘N’ prompt.
> 
> Is there a way to just skip the prompt and specify ‘Y’ for everything?

You can use the “–include-dependencies” option. You will have trouble  
with  
platform specific gems, though, as it will ask you to pick a version.  
You  
can probably specify the specific version in those cases, though.

Justin

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 27, 2006, 11:03pm UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/3 "2006-11-27T23:03:00Z")

</div>

Quoting S.n Hansen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Let’s say I have the following task and I want it to run on a remote  
> Is there a way to just skip the prompt and specify ‘Y’ for everything?  
> Could you use the Unix ‘yes’ command?

man yes

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 27, 2006, 11:13pm UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/4 "2006-11-27T23:13:01Z")

</div>

Justin B. wrote:

> with  
> platform specific gems, though, as it will ask you to pick a version. You  
> can probably specify the specific version in those cases, though.
> 
> Justin

Sweet, that’s exactly what I was looking for.

-Steven

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 27, 2006, 11:41pm UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/5 "2006-11-27T23:41:05Z")

</div>

Instead of:

run “gem install rails”

use:

run “gem install rails -y”

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 27, 2006, 11:41pm UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/6 "2006-11-27T23:41:06Z")

</div>

Instead of:

run “gem install rails”

use:

run “gem install rails -y”

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 28, 2006, 2:55am UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/7 "2006-11-28T02:55:31Z")

</div>

On Nov 27, 2006, at 1:56 PM, Steven H. wrote:

> Is there a way to just skip the prompt and specify ‘Y’ for everything?
> 
> Regards,  
> Steven

Hey Steven-

```
Here is a capistrano plugin for installing gems remotely. This

```

supports slecting gem versions or letting it pick from the list  
itself when it gets presented with a list of choices it will choose  
the correct latest version based on architecture.

```
This is code adapted and extracted from the vmgen gem for generating

```

Xen instances.

require ‘capistrano’

# Installs within Capistrano as the plugin _gem_.

# Prefix all calls to the library with gem.

# Manages installing gems and versioned gems.

module Gem

# Default install command

# 

# \* doesn’t install documentation

# \* installs all required dependencies automatically.

# 

GEM\_INSTALL=“gem install -y --no-rdoc”

# Upgrade the _gem_ system to the latest version. Runs via _sudo_

def update\_system  
sudo “gem update --system”  
end

# Updates all the installed gems to the latest version. Runs via

_sudo_.

# Don’t use this command if any of the gems require a version

selection.  
def upgrade  
sudo “gem update --no-rdoc”  
end

# Removes old versions of gems from installation area.

def cleanup  
sudo “gem cleanup”  
end

# Installs the gems detailed in +packages+, selecting version

+version+ if

# specified.

# 

# +packages+ can be a single string or an array of strings.

# 

def install(packages, version=nil)  
sudo “#{GEM\_INSTALL} #{if version then '-v ‘+version.to\_s end} #  
{packages.to\_a.join(’ ')}”  
end

# Auto selects a gem from a list and installs it.

# 

# _gem_ has no mechanism on the command line of disambiguating

builds for

# different platforms, and instead asks the user. This method has

the necessary

# conversation to select the +version+ relevant to +platform+ (or

the one nearest

# the top of the list if you don’t specify +version+).

def select(package, version=nil, platform=‘ruby’)  
selections={}  
cmd="#{GEM\_INSTALL} #{if version then '-v '+version.to\_s end} #  
{package}"  
sudo cmd do |channel, stream, data|  
data.each\_line do | line |  
case line  
when /\s(\d+).\*(#{platform})/  
if selections[channel[:host]].nil?  
selections[channel[:host]]=$1.dup+"\n"  
logger.info “Selecting #$&”, “#{stream} :: #{channel[:host]}”  
end  
when /\s\d+./  
# Discard other selections from data stream  
when /^\>/  
channel.send\_data selections[channel[:host]]  
logger.debug line, “#{stream} :: #{channel[:host]}”  
else  
logger.info line, “#{stream} :: #{channel[:host]}”  
end  
end  
end  
end

end

Capistrano.plugin :gem, Gem

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 29, 2006, 2:09am UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/8 "2006-11-29T02:09:26Z")

</div>

On Nov 28, 2006, at 4:41 PM, Steven H. wrote:

> Kind Regards,  
> Steven

Hey Steven-

```
It really doesn't matter where you put it as long as it is in the

```

load path so you can require it in your recipe file. So lib is a fin  
place to put it.

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [November 29, 2006, 1:43am UTC](https://www.ruby-forum.com/t/automating-installation-of-gems-on-remote-machine-with-capis/77426/9 "2006-11-29T01:43:22Z")

</div>

Ezra Z. wrote:

> > The problem I’m having is that when you install a gem from the
> 
> # Installs within Capistrano as the plugin _gem_.
> 
> ```
> sudo "gem update --no-rdoc"
> 
> ```
> 
> # 
> 
> builds for  
> data.each\_line do | line |  
> logger.debug line, “#{stream} :: #{channel[:host]}”
> 
> Cheers-  
> – Ezra Z.-- Lead Rails Evangelist  
> – removed\_email\_address@domain.invalid  
> – Engine Y., Serious Rails Hosting  
> – (866) 518-YARD (9273)

Ezra,

Thank you! 🙂

One question, is there a standard location to put capistrano plugins?  
The capistrano manual didn’t mention anything about this so I suppose I  
could just stick it in my app’s lib dir?

Kind Regards,  
Steven
