1

我正在通过 Michael Hartl 的 Ruby on Rails教程学习 Rails :https ://www.railstutorial.org/book

我使用以下命令生成控制器:

rails generate controller StaticPages home help

这会产生以下有关版本冲突的错误:

check_version_conflict': can't activate bundler-1.12.4, already
activated bundler-1.13.0.pre.1 (Gem::LoadError)

我不知道要使用哪个捆绑器版本。当前版本的捆绑器是:1.13.pre.1


由于大约五个无法自动安装的 gem 依赖项,以下命令继续失败,其中包括listennokigiri.

bundle install --without production

我尝试手动安装依赖的 gem,但我仍然遇到问题。

如何解决生成 Rails 控制器时的check_version_conflict问题?Bundler

我将接受一个指示删除当前 Ruby 库并从头开始安装新开发环境的答案。

4

2 回答 2

2

Bundler 将安装特定于项目的 gems 版本,这样您就不必管理全局依赖项。

实际上,如果您使用 bundler 安装 Rails,并且还使用sudo gem install rails类似的东西安装它,您的计算机上将有两个版本。默认情况下,调用rails将引用全局版本。

如果您调用bundle exec rails(或bundle exec <gem_name>),它将调用特定于捆绑器的版本。

于 2016-06-26T16:36:39.020 回答
1

解决 Bundler 问题的十个步骤

  1. (可选)卸载 Ruby。有很多方法可以做到这一点,这里有一个:https ://superuser.com/questions/194051/how-to-completely-remove-ruby-ruby-gems-on-mac-os-x-10-6-4
  2. (可选)rbenv用于安装 Ruby。按照此处的说明进行操作:https ://github.com/rbenv/rbenv
  3. 创建一个 repo 目录来存放你未来的 Rails 应用程序

从命令行:

mkdir repo
cd repo
  1. 安装 Bundler 并为该目录创建一个 Gemfile

从命令行:

gem install bundler
bundle init
  1. 用你的编辑器打开repo/Gemfile,并配置它以指示 Bundler 安装哪个版本的 Rails

repo/Gemfile

source "https://rubygems.org"                                

gem "rails", "4.2.6"
  1. 通过 Bundler 安装 Rails

从命令行:

bundle install
  1. 使用 Bundler 创建一个新的 Rails 应用程序,然后cd进入它

从命令行:

bundle exec rails new whatevs
cd whatevs
  1. 默认情况下,您的 Rails 应用程序将有一个 Gemfile。打开它并添加您希望在您的应用程序中使用的宝石。

repo/whatevs/Gemfile

gem 'nokogiri', '1.6.8'
  1. repo/whatevs/目录中,通过 Bundler 安装应用程序的 Gems

从命令行:

bundle install
  1. repo/whatevs/目录中,生成一个控制器

从命令行:

bundle exec rails generate controller static_pages home help
于 2016-06-26T17:51:26.370 回答