使用capistrano在EC2 Amazon Unix上安装ruby

时间:2014-04-19 15:07:53

标签: ruby amazon-ec2 rvm capistrano

我正在尝试使用capistrano again安装ruby 1.9.3-p545。一年前对我有用的东西似乎被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

看起来rvm autolibs enable不再起作用,因为我收到以下错误消息:

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]`

我认为必须有其他人,使用capistrano安装ruby。我试图从源代码安装ruby,但后来我遇到了缺少yaml支持的问题。

任何想法,任何指示?

1 个答案:

答案 0 :(得分:0)

所以,这是我没有rmv的解决方案。如果您有任何改进,想法或批评,请告诉我:

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