【问题标题】:vagrant will not use rbenv ruby versionvagrant 不会使用 rbenv ruby​​ 版本
【发布时间】:2013-03-13 07:04:07
【问题描述】:

我正在使用 Vagrant 盒子:

https://dl.dropbox.com/u/14292474/vagrantboxes/precise64-ruby-1.9.3-p194.box

它在 rbenv 下安装了 ruby​​1.9.3。我正在尝试测试一个 Rails 应用程序,并且在我拥有的 chef-solo 配置器中(除其他外),这个块:

execute 'install' do
  action :run
  command "bundle install --path #{node.app_name.lib_path}/vendor/bundle --binstubs"
  cwd node.app_name.path 
end

rbenv 安装在 vagrant 用户下,并指示全局使用 1.9.3。出于某种原因,当在 vagrant up 期间运行 bundler 时,它仍然使用仅在 /opt/vagrant_ruby 中找到的 1.8.7。

我如何告诉 vagrant 我想使用 rbenv ruby​​ 来执行所有任务。我需要在 execute 块的 env 选项中传递一些东西吗?

【问题讨论】:

  • 我遇到了同样的问题,原因是 $RBENV_ROOT 没有通过 vagrant ssh 连接添加到 $PATH。我尝试将它添加到 /etc/profile 但没有得到任何爱,事实上它完全扼杀了 vagrant 的 ssh 能力

标签: ruby bundler vagrant chef-solo


【解决方案1】:

首先开始在你的服务器中获取bundle的路径:

$ which bundle
/opt/rbenv/shims/bundle

然后,知道在 chef 中包含 rbenv 食谱时,常量 RBENV_ROOT 等于 /opt/rbenv,修改你的命令如下:

command "#{RBENV_ROOT}/shims/bundle install --path #{node.app_name.lib_path}/vendor/bundle --binstubs"

所以你确保在安装时使用正确版本的 bundle。

您可以做的第二件事是在您使用的用户的 ~/.bashrc 顶部添加 rbenv 的路径(可以位于 /etc/profile.d/rbenv 但取决于您的安装)与厨师独奏

例如,如果您使用的是“部署器”,请编辑 /home/deployer/.bashrc 以使其位于文件顶部:

#Rbenv path for remote shells
source /etc/profile.d/rbenv.sh    # <--- adapt this to your installation

# If not running interactively, don't do anything
[ -z "$PS1" ] && return    # <--- remote shell (ssh connection) will stop at this line

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多