Fixing Bundler Issues After a macOS Sierra Upgrade

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 --install-dir directives.

An error occurred while installing pg (0.18.4), and Bundler cannot continue.

gem install --install-dir vendor/bundle pg -v 0.18.4 -- --with-pg-config=/Applications/

Alternatively, you can configure this setting with bundle config

An error occurred while installing nokogiri (1.6.8), and Bundler cannot continue. An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue. xcode-select --install

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

Continue Reading

Fixing Invalid DATABASE_URL Reference on CircleCI

I’ve become a huge fan of CircleCI—it’s the best CI tool for small-medium projects that I’ve found. Recently I ran into an issue setting up a new rails project with Postgres as the database backend with circle:

export RAILS_ENV="test" export RACK_ENV="test" bundle exec rake db:create db:schema:load --trace ** Invoke db:create (first_time) ** Invoke db:load_config (first_time) ** Execute db:load_config rake aborted! NameError: Cannot load `Rails.application.database_configuration`: uninitialized constant DATABASE_URL

However, when I looked at my database.yml the constant DATABASE_URL was clearly not being used. DATABASE_URL was properly being used as the lookup string for an ENV reference:

# config/database.yml test: url: <%= ENV['TEST_DATABASE_URL'] %>

I was stumped for a while until I ssh’d into circle and noticed that somehow the single quotes were stripped from DATABASE_URL:

# cat config/database.yml test: url: <%= ENV[DATABASE_URL] %> adapter: postgresql database: circle_ruby_test username: ubuntu host: localhost

Circle’s build inference process involves generating a database.yml file which uses the original database.yml file to some extent. Some part of the process involves stripping single quotes, which is what was causing the build breakage. Make sure that you use double quotes instead of single quotes in database.yml when using CircleCI.

Automating Staging Deploys to Staging on CI Build Success

Here’s how to automatically push new builds (and run database migrations) to a heroku-hosted app using circle CI:

deployment: staging: branch: master commands: - heroku maintenance:on --app the-app-name - git push $CIRCLE_SHA1:master - heroku run rake db:migrate --app the-app-name - heroku maintenance:off --app the-app-name

Continue Reading

MacRuby 0.12, RVM, and Gem Installation Problems

I recently jumped back into a MacRuby project that I haven’t touched in a while. I upgraded to the latest MacRuby 0.12, installed the necessary gems via macgem install, and was presented with this error:[code]Segmentation fault: 11[/code]

Since I started this project my ruby setup had drastically changed: RVM, custom irbrc, and lots of other tools that I’ve found essential for productive rails development had been installed. I noticed that macgem list --local returned the list of gems needed for my rails project.

Running env from the command line revealed that GEM_HOME and GEM_PATH were set explicitly in my bash env, a result of having RVM installed and a non-system ruby set as default. These two environment variables were causing macgem to look for and install gems in the rvm gem directory. To fix the issue run these two commands in your shell and then run your necessary macgem install commands:[code]unset GEM_PATH unset GEM_HOME[/code]

Continue Reading