Search code examples
rubyamazon-ec2rvmcapistrano

installing ruby on EC2 Amazon Unix, using capistrano


I'm trying to install ruby 1.9.3-p545 using capistrano again. What worked for me a year ago, seems to be broken by rvm:

require "rvm/capistrano"

set :rvm_ruby_string, 'ruby-1.9.3-p327'
set :rvm_type, :user
set :rvm_install_ruby_params, '--with-opensll-dir=$HOME/.rvm/usr'

def rvm_bin
    '$HOME/.rvm/bin/rvm'
end

namespace :deploy do
    task :step do
        rvm.install_rvm
        run "#{rvm_bin} autolibs enable"
        rvm.install_ruby
        run "#{rvm_bin} alias create default #{rvm_ruby_string}"
        run 'echo "source ~/.rvm/environments/default" >> $HOME/.bashrc'
        run 'which ruby && ruby -v'
        run 'gem install --no-ri --no-rdoc rake rack net-ssh bundler'
    end
end

It looks like the rvm autolibs enable doesn't work anymore, because I get the following error message:

Checking requirements for amazon.
Missing required packages: libyaml-devel libffi-devel readline-devel openssl-devel bison
RVM autolibs is now configured with mode '2' => 'check and stop if missing',
please run `rvm autolibs enable` to let RVM do its job or run and read `rvm autolibs [help]`

I think there must be others out there, using capistrano to install ruby. I've tried to install ruby from sources, but then I ran into problems with missing yaml support.

Any thoughts, any pointers?


Solution

  • So, this is my solution without rmv. Please let me know, if you have any improvements, thoughts or critics:

    namespace :deploy do
        RUBY_VERSION = 'ruby-1.9.3-p545'
    
        task :step do
            # remove default ruby and install dependencies     
            run "#{sudo} yum erase --assumeyes ruby"
            run "#{sudo} yum install --assumeyes readline-devel openssl-devel libyaml-devel"
            # Add the installed ruby to PATH
            run "echo 'export PATH=$PATH:$HOME/bin' >> $HOME/.bashrc"
            run "source $HOME/.bashrc"
            # Build and install
            run "wget http://cache.ruby-lang.org/pub/ruby/1.9/#{RUBY_VERSION}.tar.gz"
            run "tar zxvf #{RUBY_VERSION}.tar.gz"
            run "cd #{RUBY_VERSION} && ./configure --disable-install-doc --enable-shared --prefix=$HOME && make && make install"
            # Check installation and install very basic gems
            run 'which ruby && ruby -v'
            run "gem install --no-ri --no-rdoc rake rack net-ssh bundler"
        end
    end