在CentOS 6.5上安装Ruby 2.1.1 / Rails 4.0.4

时间:2014-05-18 02:00:13

标签: ruby ruby-on-rails-4 rvm chef

这是我的食谱:

execute "rvm-install" do
  user "root"
  command "curl -sSL https://get.rvm.io | bash -s stable --ruby=2.1.1"
  action :run
end

...... PASS

%w{ruby-devel rubygems}.each do |pkg|
  package pkg do
    action :install
  end
end

...... PASS

execute "gem-update-system" do
  user "root"
  command "gem update --system"
  action :run
end

...... PASS

execute "ruby-1.9.3-install" do
  user "root"
  command "rvm install 1.9.3"
  action :run
end

......失败

 * execute[ruby-1.9.3-install] action run
================================================================================
Error executing action `run` on resource 'execute[ruby-1.9.3-install]'
================================================================================


Errno::ENOENT
-------------
No such file or directory - rvm install 1.9.3

...最终我想这样做

execute "rails-install" do
  user "root"
  command "gem install rails 4.0.4 -V"
  action :run
end

我尝试在--rails中传递rvm-install,但这种情况很糟糕。

希望我能得到一些帮助。

2 个答案:

答案 0 :(得分:1)

Chef默认情况下从不加载用户环境,因此命令运行时$ PATH(或$ HOME)不可用。您可以做的最好的事情是指定要运行的命令的完整路径,如果需要加载某些环境变量,可以使用以下命令执行此操作:

execute "Executing a command with ENV variables" do
  command "/tmp/foo.sh"
  user "MY_USERNAME"
  environment ({ 'HOME' => ::Dir.home('MY_USERNAME'), 'USER' => 'MY_USERNAME', 'FOO' => 'BAR' })
end

请参阅:https://tickets.opscode.com/browse/CHEF-2288

答案 1 :(得分:0)

除了@ daniel的回答之外,在包装器脚本中提供RVM脚本可能很有用,这样您的整个环境就可以使用了.ruby-version.ruby-gemsets个文件。例如)

#!/bin/sh
source $HOME/.rvm/scripts/rvm
/path/to/my/super/awesome.sh

ķ