Issue #15469 has been updated by aeroastro (Takumasa Ochi).


I have found out the root cause of this.

# Root Cause

* Bundler has become a built-in gem since Ruby 2.6.
* `$LOAD_PATH` required for bundler is moved from custom gem path ( e.g. `lib/ruby/gems/2.5.0/gems/bundler-1.17.2/lib` ) to ruby built-in gem path ( `lib/ruby/2.6.0` )
* In the same path, `csv`, `json`, and other built-in gems are located.
* When invoked via `bundler`, this path for `bundler` is inserted at the head of `$LOAD_PATH`, which takes precedence over all the other paths.
* These built-in gems are loaded instead of those specified by `Gemfile`.

# Why Workaround Works

When bundler is updated by `gem install`, the `$LOAD_PATH` is moved from ruby built-in gem path to custom gem path.
This fixes shared built-in gem path issue.

# Suggested Fix

IMHO, moving bundler to isolated path instead of shared built-in path would fix this issue.


# Bug Detail

Following are the code to reproduce and explain this issue.

## Gemfile

```ruby
source "https://rubygems.org"

gem 'json', '~> 1.8.6'
```

## Code

```ruby
before = $LOADED_FEATURES.dup
require 'json'
after = $LOADED_FEATURES.dup

require 'yaml'

puts YAML.dump(
  ruby: RUBY_VERSION,
  bundler: (Bundler::VERSION rescue nil),
  json: JSON::VERSION,
  load_path: $LOAD_PATH,
  added_features: after - before,
)

JSON.dump("GET")
```

## Result

```
# I have installed ruby with rbenv and ruby-build
# `bundle install --path=vendor/bundle` is executed as prerequisites

$ rbenv shell 2.5.3 && bundle exec ruby test.rb
---
:ruby: 2.5.3
:bundler: 1.17.2
:json: 1.8.6
:load_path:
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.2/lib"
- "/Users/user-name/.rbenv/rbenv.d/exec/gem-rehash"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-16/2.5.0-static/json-1.8.6"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.2/lib/gems/bundler-1.17.2/lib"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/x86_64-darwin16"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/site_ruby"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/vendor_ruby/2.5.0"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/vendor_ruby/2.5.0/x86_64-darwin16"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/vendor_ruby"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/2.5.0"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin16"
:added_features:
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib/json/version.rb"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/2.5.0/ostruct.rb"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib/json/generic_object.rb"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib/json/common.rb"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin16/enc/utf_16be.bundle"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin16/enc/utf_16le.bundle"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin16/enc/utf_32be.bundle"
- "/Users/user-name/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin16/enc/utf_32le.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib/json/ext/parser.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib/json/ext/generator.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib/json/ext.rb"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.5.0/gems/json-1.8.6/lib/json.rb"

$ rbenv shell 2.6.0 && bundle exec ruby test.rb
---
:ruby: 2.6.0
:bundler: 1.17.2
:json: 2.1.0
:load_path:
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0"
- "/Users/user-name/.rbenv/rbenv.d/exec/gem-rehash"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-16/2.6.0-static/json-1.8.6"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/lib"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/site_ruby/2.6.0"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/site_ruby/2.6.0/x86_64-darwin16"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/site_ruby"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/vendor_ruby/2.6.0"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/vendor_ruby/2.6.0/x86_64-darwin16"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/vendor_ruby"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16"
:added_features:
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json/version.rb"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/ostruct.rb"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json/generic_object.rb"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json/common.rb"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_16be.bundle"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_16le.bundle"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_32be.bundle"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_32le.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/ext/parser.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/ext/generator.bundle"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json/ext.rb"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json.rb"
Traceback (most recent call last):
	3: from test.rb:15:in `<main>'
	2: from /Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json/common.rb:394:in `dump'
	1: from /Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json/common.rb:224:in `generate'
/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/json/common.rb:224:in `generate': only generation of JSON objects or arrays allowed (JSON::GeneratorError)

$ gem install bundler -v 1.17.3
Fetching bundler-1.17.3.gem
Successfully installed bundler-1.17.3
Parsing documentation for bundler-1.17.3
Installing ri documentation for bundler-1.17.3
Done installing documentation for bundler after 3 seconds
1 gem installed

$ rbenv shell 2.6.0 && bundle exec ruby test.rb
---
:ruby: 2.6.0
:bundler: 1.17.3
:json: 1.8.6
:load_path:
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/lib"
- "/Users/user-name/.rbenv/rbenv.d/exec/gem-rehash"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-16/2.6.0-static/json-1.8.6"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/lib/gems/bundler-1.17.3/lib"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/site_ruby/2.6.0"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/site_ruby/2.6.0/x86_64-darwin16"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/site_ruby"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/vendor_ruby/2.6.0"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/vendor_ruby/2.6.0/x86_64-darwin16"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/vendor_ruby"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16"
:added_features:
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/version.rb"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/ostruct.rb"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/generic_object.rb"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/common.rb"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_16be.bundle"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_16le.bundle"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_32be.bundle"
- "/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-darwin16/enc/utf_32le.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/ext/parser.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/ext/generator.bundle"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json/ext.rb"
- "/Users/user-name/temp/aiueo/vendor/bundle/ruby/2.6.0/gems/json-1.8.6/lib/json.rb"
```

You can see the first element in `$LOAD_PATH` is problematic when built-in `bundler` is used. ( `/Users/user-name/.rbenv/versions/2.6.0/lib/ruby/2.6.0` )
`json` in shared built-in gem path is required instead of Gemfile-specified `json` gem.

(The exception above is caused by mixed versions of `json` gem.)

----------------------------------------
Bug #15469: Ruby2.6 included `bundler` does not handle specified `csv` gem.
https://bugs.ruby-lang.org/issues/15469#change-76478

* Author: watson1978 (Shizuo Fujita)
* Status: Assigned
* Priority: Normal
* Assignee: hsbt (Hiroshi SHIBATA)
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
I want to use `csv` library which is same version of Ruby 2.5.
Because Ruby 2.6's csv library has some breaking changes and they break our product.

However, Ruby 2.6's `bundler` does not handle `csv` which I specified the version.

## Test code

* Gemfile

```
source "https://rubygems.org"

gem 'roo'
gem 'csv', '1.0.0'
```

* test.rb

```
require "bundler/setup"
require "csv"

p CSV::VERSION
```

## Result

```
$ bundle exec ruby -v test.rb
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
"3.0.2"
```

`CSV::VERSION` shows `3.0.2` and  it indicates that Ruby 2.6 included `csv` library was used.

## Workaround
If I install the `bundler` gem through `gem install bundler`, it works well.

```
$ gem install bundler
Fetching bundler-1.17.3.gem
Successfully installed bundler-1.17.3
1 gem installed

$ bundle exec ruby -v test.rb
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
"2.4.8"
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>