skip to Main Content

thank you for taking the time to read this. I’m extremely new to this, and am currently following a textbook for learning Rails, so apologies if I’m slow to pick up instruction. I’m currently on Chapter 5 of the Ruby on Rails tutorial (3rd edition), and part of this is my fault as I fiddled with something (I’m not exactly sure what) and now I get this error: I’m trying to install Bootstrap, and I was supposed to add a line of code in my gemfile. But now every time I try to run bundle install, I receive this error.

[!] There was an error parsing `Gemfile`: You cannot specify the same gem twice with different version requirements.
You specified: rails (= 4.2.2) and rails (~> 6.0.3, >= 6.0.3.1). Bundler cannot continue.

 #  from /home/ubuntu/environment/sample_app/Gemfile:10
 #  -------------------------------------------
 #  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
 >  gem 'rails', '~> 6.0.3', '>= 6.0.3.1'
 #  # Use sqlite3 as the database for Active Record
 #  -------------------------------------------

I know it’s probably something basic and obvious, but I would appreciate explicit instruction because I’m completely lost. Any and all help is appreciated! This is what my Gemfile looks like:

source 'https://rubygems.org'

gem 'rails',                '4.2.2'
gem 'bootstrap-sass',       '3.2.0.0'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# 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.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '> = 4.1.2', require: false

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

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]


2

Answers


  1. As the error message says, you have a couple of declarations for the rails gem.

    Remove gem 'rails', '4.2.2' (at the top of the file, after source 'https://rubygems.org') and run bundle install (or just bundle).

    Hope this helps!

    Login or Signup to reply.
  2. Rails is defined twice on your Gemfile.

    First on line 3 and the second on line 10. Just remove the first from line 3 and try bundle install again.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search