Posted by Chris Blackburn Tue, 01 Jan 2008 03:27:00 GMT

So you’ve tried

 sudo gem install rjb

and it just won’t work?

How about:

 export JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Home'
 sudo gem install rjb

Still won’t work?

That’s because sudo won’t inherit the JAVA_HOME variable. Try this:

 sudo su -
 export JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Home'
 gem install rjb

…now enjoy the RJB gem. :)

Posted by admin Mon, 16 Apr 2007 23:09:00 GMT

Managing a distributed Rails application without Capistrano is painful at best. If you have ever had to do it you know what I am talking about.

Capistrano makes things much easier. Case in point is updating your gems across multiple servers. Here is the Capistrano recipe that we use to keep gems updated:

desc "Update ruby gems"
task :update_gems, :roles => [:web, :admin, :app] do
  cmd = "/usr/local/bin/gem update --include-dependencies"
  sudo cmd do |channel, stream, data|
    puts "#{channel[:host]}: #{data}"
    if data =~ /([12])\.[^\(]+\(ruby\)/
      channel.send_data "#{$1}\n"
    end
  end
end

Now, you’ll probably need to customize it to your own needs. For instance, change the roles to suit your own setup. Also, you may want to modify the path to your ‘gem’ executable, and configure ’sudo’ to allow your user to run that command without a password. You’ll have to do that on each server as follows:

sudo visudo
Then add a line like this:
myuser ALL=(ALL) NOPASSWD: /usr/local/bin/gem update --include-dependencies

If you don’t have access to ‘visudo’ ask your administrator.

Also, Win32 users will need to change the regular expression from this:

if data =~ /([12])\.[^\(]+\(ruby\)/

to this:

if data =~ /([12])\.[^\(]+\(mswin32\)/

… so Capistrano will choose the correct version of the gem to use.

Basically this recipe will run the ’gem update --include-dependencies’ command and analyze the output choosing the correct latest version of gem to install.

Older posts: 1 2