I recently upgraded my laptop, and with that came setting up a fresh dev machine. With a fresh install always comes with a set of development configuration problems. Here’s some tips of resolving ruby bundler issues in MacOS Sierra.
These tips assume you are using dotfiles that look similar to these. Also, I prefer fresh installs, so I never pull config from my old machine/OS. These fixes may not work if you are migrating configuration from a previous OS.
For any of the fixes outlined below:
- Adjust the version strings based on your project
- If you do not have bundler’s shared gems disabled, then you can omit the
An error occurred while installing pg (0.18.4), and Bundler cannot
gem install --install-dir vendor/bundle pg -v 0.18.4 -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.6/bin/pg_config
Alternatively, you can configure this setting with bundle config build.pg.
- An error occurred while installing nokogiri (1.6.8), and Bundler cannot
- An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue.
An error occurred while installing capybara-webkit (1.11.1), and
Bundler cannot continue.
brew install qt55 brew link --force qt55
Then, I needed to manually edit
mkspecs/features/Mac/default_pre.prf. More details here.
error occurred while installing therubyracer (0.12.1), and Bundler cannot continue
gem install --install-dir vendor/bundle libv8 -- --with-system-v8 gem install --install-dir vendor/bundle therubyracer -v 0.12.1
rubygems/core_ext/kernel_require.rb:54:in `require’: cannot load such file — bundler/setup (LoadError)
This is caused by spring coupled with a new version of bundler. Regenerate your binstubs:
bundle exec spring binstub --all
Enter passphrase for /Users/USER/.ssh/id_rsa
If you copy your public + private key from your old machine/OS, and used a passphrase to secure it (which you should be doing!), you’ll need to run this command to avoid reentering your passphrase every time you use the key:
ssh-agent bash ssh-add # in some cases (capistrano deployment, for example) you'll need to do this: ssh-add -K ~/.ssh/id_rsa # Also, in some cases, this helped: edit ~/.ssh/config Host * UseKeychain yes
An error occurred while installing eventmachine (1.0.4), and Bundler cannot continue.
Specifically, I got this build error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension. ~/.rbenv/versions/2.1.6/bin/ruby extconf.rb checking for rb_trap_immediate in ruby.h,rubysig.h... no creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling binder.cpp In file included from binder.cpp:20: ./project.h:112:10: fatal error: 'openssl/ssl.h' file not found #include <openssl/ssl.h> ^ 1 error generated. make: *** [binder.o] Error 1 make failed, exit code 2
Here’s the fix (inspired by this post) that fixed the issue:
gem install --install-dir vendor/bundle eventmachine -v '1.0.4' -- --with-cppflags=-I/usr/local/opt/openssl/include
/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require’: cannot load such file — bundler/setup (LoadError)
This error was being caused by spring when attempting to run
bundle exec rails console. You can verify that this is the case by omitting spring with
export DISABLE_SPRING=true and seeing if rails console runs just fine.
To fix this issue, you need to update your binstubs:
bundle exec rake rails:update:bin