Roxcly
Roxcly

Reputation: 156

How to solve error "bundler could not find compatible version for gem X"

I'm trying to setup docker for my project. I have tried installing actionpack 5.0.2, but it did not do me any good. I am following a tutorial on how to setup, so I reckon there are version issues. When I run docker-compose up, this is what I get:

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

Here is my 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'

EDIT: Tried removing the gem actionpack entirely from the gemfile, caused new issues on docker-compose up:

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

Upvotes: 2

Views: 2451

Answers (3)

Tom Lord
Tom Lord

Reputation: 28285

These two lines in your Gemfile are causing a dependency conflict:

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

~> 5.0.2 means "Greater than 5.0.2 and less than 5.1.0".

'~> 5.1', '>= 5.1.1' means "Greater than 5.1.1 and less than 6.0.0.".

Hence there is a conflict, and Bundler fails to resolve. You need to either upgrade rails or downgradeactionpack.

The easiest solution is probably to just remove actionpack from the Gemfile, since you don't really need to specify it at all. actionpack is a dependency of rails, so it will be installed regardless.

I would also suggest that you remove the '~> 5.0.2' version constraint on rails, unless you have a good reason to lock down the version number.

Update regarding your second error:

This error is very similar to the above; it's quite self-explanatory.

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

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

Just like above, you have one gem that depends on actionpack version v4.x.x, and another gem that depends on actionpack v5.0.2.

You need to somehow update/loosen the version constraint in your Gemfile. For example, you could write:

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

Upvotes: 2

Murad Omar
Murad Omar

Reputation: 90

Apparently you have a dependency problem.

In your Gemfile try using:

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

Upvotes: 0

RichardAE
RichardAE

Reputation: 2970

You have specified to use actionpack greater or equal to 5.1:

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

However Rails 5.0.2 is specifically locked to actionpack 5.0.2. Remove the line above from your Gemfile, it's superfluous.

Upvotes: 2

Related Questions