title: How to work around conflicts with Ruby versions and pg gem
body: <p>I'm working on someone's website, trying to get Rails to run. The files sent to me included the gemfile, which had <code>gem 'pg', '0.21.0'. However, when I run</code>bundler install` I get</p>
  
  <pre><code>Bundler could not find compatible versions for gem "ruby ":
    In Gemfile:
      ruby  (~&gt; 2.6.6.0)
  
      pg (= 0.21.0) was resolved to 0.21.0, which depends on
        ruby  (&gt;= 2.0.0)
  
      pg (= 0.21.0) was resolved to 0.21.0, which depends on
        ruby  (&lt; 2.5, &gt;= 2.0) x64-mingw32
  </code></pre>
  
  <p>Additionally, if I try to run <code>rails server</code> or <code>rails -v</code> after such a failed attempt, I get</p>
  
  <pre><code>Could not find gem 'pg (= 0.21.0) x64-mingw32' in any of the gem sources listed in your Gemfile.
  Run `bundle install` to install missing gems.
  </code></pre>
  
  <p>I'm running Ruby 2.6.6p146 and Rails 4.2.10, although I could change the Rails version easily, and it doesn't seem to affect this. 
  I'm on Windows 10 if it helps. </p>
  
  <p>It appears I need to use a more recent version of pg. When I try that (the earliest compatible version being 1.1.4) <code>bundle install</code> works well. But then, <code>rails server</code> throws</p>
  
  <pre><code>Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
  </code></pre>
  
  <p>It appears I'm stuck between these two errors, where, based on my version of pg in the gemfile, I'm bound to get one of them, and neither allows me to run <code>rails server</code>. </p>
  
  <p>Is there a way to get around this, preferably, a solution that will allow me to keep 0.21.0 in the gemfile? I'm also happy for a solution that gets around the second error instead. </p>
  
  <p>Here's the full stack trace for the second error:</p>
  
  <pre><code>C:/Ruby26-x64/lib/ruby/2.6.0/x64-mingw32/etc.so: warning: already initialized constant Struct::Passwd
  C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/core_ext/object/duplicable.rb:111: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
  C:/Ruby26-x64/lib/ruby/2.6.0/forwardable.rb:116: warning: already initialized constant Forwardable::VERSION
  C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/forwardable-1.3.1/lib/forwardable/version.rb:3: warning: previous definition of VERSION was here
  C:/Ruby26-x64/lib/ruby/2.6.0/forwardable.rb:117: warning: already initialized constant Forwardable::FORWARDABLE_VERSION
  C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/forwardable-1.3.1/lib/forwardable/version.rb:4: warning: previous definition of FORWARDABLE_VERSION was here
  =&gt; Booting WEBrick
  =&gt; Rails 4.2.10 application starting in development on http://localhost:3000
  =&gt; Run `rails server -h` for more startup options
  =&gt; Ctrl-C to shutdown server
  Exiting
  Traceback (most recent call last):
          56: from bin/rails:4:in `&lt;main&gt;'
          55: from bin/rails:4:in `require'
          54: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands.rb:17:in `&lt;top (required)&gt;'
          53: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
          52: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75:in `server'
          51: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75:in `tap'
          50: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:80:in `block in server'
          49: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/server.rb:78:in `start'
          48: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/server.rb:139:in `log_to_stdout'
          47: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:337:in `wrapped_app'
          46: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/server.rb:61:in `app'
          45: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:209:in `app'
          44: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:300:in `build_app_and_options_from_config'
          43: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:40:in `parse_file'
          42: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:49:in `new_from_string'
          41: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:49:in `eval'
          40: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config.ru:in `&lt;main&gt;'
          39: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config.ru:in `new'
          38: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `initialize'
          37: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `instance_eval'
          36: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config.ru:3:in `block in &lt;main&gt;'
          35: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
          34: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
          33: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
          32: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
          31: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config/environment.rb:5:in `&lt;top (required)&gt;'
          30: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/railtie.rb:194:in `method_missing'
          29: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/railtie.rb:194:in `public_send'
          28: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/application.rb:352:in `initialize!'
          27: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:54:in `run_initializers'
          26: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
          25: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
          24: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
          23: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `call'
          22: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `each'
          21: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
          20: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
          19: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
          18: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
          17: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:55:in `block in run_initializers'
          16: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `run'
          15: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `instance_exec'
          14: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/railtie.rb:118:in `block in &lt;class:Railtie&gt;'
          13: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
          12: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:27:in `each'
          11: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
          10: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
           9: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
           8: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/railtie.rb:122:in `block (2 levels) in &lt;class:Railtie&gt;'
           7: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/connection_handling.rb:50:in `establish_connection'
           6: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec'
           5: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
           4: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
           3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
           2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
           1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:16:in `&lt;top (required)&gt;'
  C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem': can't activate pg (~&gt; 0.15), already activated pg-1.1.4-x64-mingw32. Make sure all dependencies are added to Gemfile. (Gem::LoadError)
          51: from bin/rails:4:in `&lt;main&gt;'
          50: from bin/rails:4:in `require'
          49: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands.rb:17:in `&lt;top (required)&gt;'
          48: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
          47: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75:in `server'
          46: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75:in `tap'
          45: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:80:in `block in server'
          44: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/server.rb:78:in `start'
          43: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/server.rb:139:in `log_to_stdout'
          42: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:337:in `wrapped_app'
          41: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/commands/server.rb:61:in `app'
          40: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:209:in `app'
          39: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/server.rb:300:in `build_app_and_options_from_config'
          38: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:40:in `parse_file'
          37: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:49:in `new_from_string'
          36: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:49:in `eval'
          35: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config.ru:in `&lt;main&gt;'
          34: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config.ru:in `new'
          33: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `initialize'
          32: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `instance_eval'
          31: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config.ru:3:in `block in &lt;main&gt;'
          30: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
          29: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
          28: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
          27: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
          26: from C:/Users/iijof/Desktop/Jobs/You3dit/y3dialpha/config/environment.rb:5:in `&lt;top (required)&gt;'
          25: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/railtie.rb:194:in `method_missing'
          24: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/railtie.rb:194:in `public_send'
          23: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/application.rb:352:in `initialize!'
          22: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:54:in `run_initializers'
          21: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
          20: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
          19: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
          18: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `call'
          17: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:347:in `each'
          16: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
          15: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
          14: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
          13: from C:/Ruby26-x64/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
          12: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:55:in `block in run_initializers'
          11: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `run'
          10: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `instance_exec'
           9: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/railtie.rb:118:in `block in &lt;class:Railtie&gt;'
           8: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
           7: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:27:in `each'
           6: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
           5: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
           4: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
           3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/railtie.rb:122:in `block (2 levels) in &lt;class:Railtie&gt;'
           2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/connection_handling.rb:50:in `establish_connection'
           1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
  C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
  </code></pre>