Rails 3.2.22 and Ruby 2.0.0 on macOS 10.14.6. App functions properly and all tests pass - Rspec, 427 tests, 0 failures.
Gems are bundled into /vendor/bundle
. I used ruby-install
to install ruby versions and chruby
to auto-switch according to a .ruby-version
file. I also define ruby version in the Gemfile
for Heroku.
# Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
...
# .ruby-version
ruby-2.0.0
When I move to Ruby 2.1.0 in the Gemfile
and .ruby-version
I can no longer bundle install
or start the app:
$ bundle install
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/bundle:22:in `<main>'
$ foreman start
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem foreman (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/foreman:22:in `<main>'
I can't install bundler:
$ gem install bundler
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
WHAT I'VE TRIED SO FAR
If I go back to Ruby 2.0.0 in 'Gemfile' and -ruby-version
the app runs but Rspec fails with lots of warning: already initialized constant
for activerecord
, activesupport
and paper_trail
, even though nothing has changed in the app, Gemfile
or Gemfile.lock
.
The only way to get it running again on Ruby 2.0.0 is to flush out the bundled gems with bundle clean --force
then a fresh bundle install
.
After the openssl
error I removed Ruby 2.1.0 from ~/.rubies/
and reinstalled with option specifying the path to my openssl
install (after finding it from brew
):
$ brew --prefix openssl@1.0
/usr/local/opt/openssl@1.0
$ ruby-install ruby 2.1.0 -- --with-openssl-dir=/usr/local/opt/openssl@1.0
Ruby 2.1.0 installed correctly and I try to install bundler
I get:
$ gem install budler
Fetching: bundler-2.1.4.gem (100%)
ERROR: Error installing bundler:
bundler requires Ruby version >= 2.3.0.
I install the specific version of bundler
that created the Gemfile.lock
:
$ gem install bundler -v "1.17.3"
Fetching: bundler-1.17.3.gem (100%)
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 8 seconds
1 gem installed
But then bundle install
fails saying that Ruby version is 2.3.7:
$ bundle install
Your Ruby version is 2.3.7, but your Gemfile specified 2.1.0
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin18.0]
Looks like the reference to Ruby 2.3.7 is coming from here:
$ bundle env
## Environment
Bundler 1.17.3
Platforms ruby, universal-darwin-18
Ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
Full Path /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Config Dir /Library/Ruby/Site
RubyGems 2.5.2.3
Gem Home /Users/dan/.gem/ruby/2.1.0
Gem Path /Users/dan/.gem/ruby/2.1.0:/Users/dan/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0
User Path /Users/dan/.gem/ruby/2.3.0
Bin Dir /Users/dan/.gem/ruby/2.1.0/bin
Tools
Git 2.20.1 (Apple Git-117)
RVM not installed
rbenv not installed
chruby 0.3.9
I found this question: Bundler using wrong Ruby version with a comment to try hash -r
:
"It could be that your shell has the old bundle command cached, try running hash -r. – matt"
This seemed to fix the hard-coded Ruby version in Bundle:
$ hash -r
$ bundle env
## Environment
Bundler 1.17.3
Platforms ruby, x86_64-darwin-18
Ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin18.0]
Full Path /Users/dan/.rubies/ruby-2.1.0/bin/ruby
Config Dir /Users/dan/.rubies/ruby-2.1.0/etc
RubyGems 2.2.0
Gem Home /Users/dan/.gem/ruby/2.1.0
Gem Path /Users/dan/.gem/ruby/2.1.0:/Users/dan/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0
User Path /Users/dan/.gem/ruby/2.1.0
Bin Dir /Users/dan/.gem/ruby/2.1.0/bin
Tools
Git 2.20.1 (Apple Git-117)
RVM not installed
rbenv not installed
chruby 0.3.9
Bundle now references Ruby 2.1.0 and I can successfully bundle install
But now I'm getting syntax errors when I run Rspec or start the app:
$ bundle exec rspec
WARNING: Nokogiri was built against LibXML version 2.9.10, but has dynamically loaded 2.9.4
/Users/dan/Documents/code/lessonmate/vendor/bundle/gems/browser-5.1.0/lib/browser/browser.rb:9:in `require_relative': /Users/dan/Documents/code/lessonmate/vendor/bundle/gems/browser-5.1.0/lib/browser/accept_language.rb:37: syntax error, unexpected '.' (SyntaxError)
code&.downcase
$ bundle exec rails server
/Users/dan/Documents/code/lessonmate/vendor/bundle/gems/uniform_notifier-1.12.0/lib/uniform_notifier.rb:3:in `require': /Users/dan/Documents/code/lessonmate/vendor/bundle/gems/uniform_notifier-1.12.0/lib/uniform_notifier/base.rb:37: syntax error, unexpected <<, expecting keyword_end (SyntaxError)
<<~CODE
^
With Ruby 2.0.0:
$RUBY_ROOT /Users/dan/.rubies/ruby-2.0.0-p648
$RUBY_ENGINE ruby
$RUBY_VERSION 2.0.0
$GEM_ROOT /Users/dan/.rubies/ruby-2.0.0-p648/lib/ruby/gems/2.0.0
$GEM_HOME /Users/dan/.gem/ruby/2.0.0
$GEM_PATH /Users/dan/.gem/ruby/2.0.0:/Users/dan/.rubies/ruby-2.0.0-p648/lib/ruby/gems/2.0.0
$PATH /Users/dan/.gem/ruby/2.0.0/bin:/Users/dan/.rubies/ruby-2.0.0-p648/lib/ruby/gems/2.0.0/bin:/Users/dan/.rubies/ruby-2.0.0-p648/bin:/Users/dan/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/dan/bin:/Users/dan/bin
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14.1
- RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [x86_64-darwin18.7.0]
- INSTALLATION DIRECTORY: /Users/dan/.gem/ruby/2.0.0
- RUBY EXECUTABLE: /Users/dan/.rubies/ruby-2.0.0-p648/bin/ruby
- EXECUTABLE DIRECTORY: /Users/dan/.gem/ruby/2.0.0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /Users/dan/.gem/ruby/2.0.0
- /Users/dan/.rubies/ruby-2.0.0-p648/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
With Ruby 2.1.0:
$RUBY_ROOT /Users/dan/.rubies/ruby-2.1.0
$RUBY_ENGINE ruby
$RUBY_VERSION 2.1.0
$GEM_ROOT /Users/dan/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0
$GEM_HOME /Users/dan/.gem/ruby/2.1.0
$GEM_PATH /Users/dan/.gem/ruby/2.1.0:/Users/dan/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0
$PATH /Users/dan/.gem/ruby/2.1.0/bin:/Users/dan/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/bin:/Users/dan/.rubies/ruby-2.1.0/bin:/Users/dan/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/dan/bin:/Users/dan/bin
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.0
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin18.0]
- INSTALLATION DIRECTORY: /Users/dan/.gem/ruby/2.1.0
- RUBY EXECUTABLE: /Users/dan/.rubies/ruby-2.1.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/dan/.gem/ruby/2.1.0/bin
- SPEC CACHE DIRECTORY: /Users/dan/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /Users/dan/.gem/ruby/2.1.0
- /Users/dan/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/dan/.gem/ruby/2.1.0/bin
- /Users/dan/.rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/bin
- /Users/dan/.rubies/ruby-2.1.0/bin
- /Users/dan/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/dan/bin
- /Users/dan/bin