【问题标题】:Setting up development vagrant box for Rails为 Rails 设置开发 vagrant box
【发布时间】:2014-11-22 22:51:23
【问题描述】:

我正在使用 Ansible 在 Vagrant 中设置一个开发 Rails 盒子。一切都设置好了,我已经使用 Rbenv 来促进 Ruby 的安装。我安装了 Ruby 2.1.2

当我运行rbenv global 时,我得到2.1.2。当我导航到我的应用程序目录并运行rbenv local 时,我得到2.1.2,当我运行ruby -v 时,我得到2.1.2。我的 gemfile 还声明了2.1.2

但是,当我运行 bundle install 时,我得到:

您的 Ruby 版本是 1.8.7,但您的 Gemfile 指定的是 2.1.2

有什么办法解决这个问题吗?

【问题讨论】:

  • bundle install 使用来自 rbenvbundle?听起来它使用了来自ruby 的系统安装的系统 gem。
  • 如何检查?
  • which bundle 的输出说明了什么?
  • /opt/vagrant_ruby/bin/bundle

标签: ruby-on-rails ruby vagrant rbenv


【解决方案1】:

您需要使用 rbenv gem 命令安装 bundle gem:

rbenv global 2.1.2

# ensure all shims for current ruby version are there
rbenv rehash

gem install bundler

# rehash again to make sure you get the `bundler` command from `rbenv`
rbenv rehash

bundle install

希望对你有帮助

【讨论】:

  • 当我尝试运行rbenv rehash时,我得到rbenv: cannot rehash: /usr/local/rbenv/shims/.rbenv-shim exists
  • 好吧,试着做gem install bundler。然后which bundler 确保它是rbenv 版本。
  • 另外,检查/usr/local/rbenv 的权限,如果 rbenv 无法写入它应该能够写入的某个地方,则可能会发生rehash 错误。你是root吗?
  • whoami 举报vagrant
  • 很好解释。运行sudo rbenv rehash
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
  • 2014-12-06
  • 1970-01-01
相关资源
最近更新 更多