如何解决错误“bundler找不到gem X的兼容版本”

时间:2017-05-26 10:05:39

标签: ruby-on-rails ruby docker rubygems

我正在尝试为我的项目设置docker。我已经尝试安装actionpack 5.0.2,但它对我没有任何帮助。我正在按照如何设置的教程,所以我认为存在版本问题。当我运行docker-compose时,这就是我得到的:

Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
  rails (~> 5.0.2) ruby depends on
  actionpack (= 5.0.2) ruby

  actionpack (>= 5.1.1, ~> 5.1) ruby

这是我的Gemfile:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end
gem 'devise'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '>= 3.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', :platforms => :ruby

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'unicorn', '~> 4.9'
gem 'pg', '~> 0.18.3'
gem 'sidekiq', '~> 4.0.1'
gem 'redis-rails', '~> 4.0.0'
gem 'actionpack', '~> 5.1', '>= 5.1.1'

编辑:尝试完全从gemfile中删除gem actionpack,导致docker-compose的新问题:

Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    rails (~> 5.0.2) ruby depends on
      actioncable (= 5.0.2) ruby depends on
        actionpack (= 5.0.2) ruby

    rails (~> 5.0.2) ruby depends on
      actioncable (= 5.0.2) ruby depends on
        actionpack (= 5.0.2) ruby

    rails (~> 5.0.2) ruby depends on
      actioncable (= 5.0.2) ruby depends on
        actionpack (= 5.0.2) ruby

    rails (~> 5.0.2) ruby depends on
      actioncable (= 5.0.2) ruby depends on
        actionpack (= 5.0.2) ruby

    redis-rails (~> 4.0.0) ruby depends on
      redis-actionpack (~> 4) ruby depends on
        actionpack (~> 4) ruby
ERROR: Service 'drkiq' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 6

3 个答案:

答案 0 :(得分:2)

您已指定使用大于或等于5.1的actionpack:

gem 'actionpack', '~> 5.1', '>= 5.1.1'

但是Rails 5.0.2专门锁定到actionpack 5.0.2。从Gemfile中删除上面的行,这是多余的。

答案 1 :(得分:0)

显然你有依赖性问题。

在您的Gemfile中尝试使用:

gem 'rails', '~> 5.1.0'
gem 'actionpack', '~> 5.1.1'

答案 2 :(得分:0)

Gemfile中的这两行导致依赖冲突:

gem 'rails', '~> 5.0.2'
gem 'actionpack', '~> 5.1', '>= 5.1.1'

~> 5.0.2表示“大于5.0.2且小于5.1.0”。

'~> 5.1', '>= 5.1.1'表示“大于5.1.1且小于6.0.0。”。

因此存在冲突,Bundler无法解决。您需要升级rails或降级actionpack

最简单的解决方案可能只是actionpack 删除Gemfile,因为您根本不需要指定它。 actionpackrails的依赖关系,因此无论如何都会安装。

我还建议您删除'~> 5.0.2' 上的rails版本约束,除非您有充分理由锁定版本号。

关于您的第二个错误的更新:

此错误与上述非常相似;这是不言自明的。

rails (~> 5.0.2) ruby depends on
  [...]
    actionpack (= 5.0.2) ruby

redis-rails (~> 4.0.0) ruby depends on
  [...]
    actionpack (~> 4) ruby

就像上面一样,你有一个依赖于actionpack版本v4.x.x的gem,以及另一个依赖于actionpack v5.0.2的gem。

您需要以某种方式更新/放宽Gemfile中的版本约束。例如,您可以写:

gem 'redis-rails', '~> 5.0'