[Ruby] What to do when ffi installation fails when starting an application with Rails

less than 1 minute read

I successfully installed the Rails version with Ruby on Rails, but when I started the Rails application, the ffi installation failed as follows. Leave the countermeasures taken at that time.

Error message

An error occurred while installing ffi (1.13.1), and Bundler cannot continue.
Make sure that `gem install ffi -v '1.13.1' --source'https://rubygems.org/'` succeeds before bundling.

Cause

Probably due to the Mojave environment of MacOS. As a cause, it seems that there is no ffi when installing Ruby with Homebrew.

Solution

First, since there is no ffi, reinstall libffi for Mojave. Reinstall using the following method.

brew reinstall libffi

However, as it is currently in a place where the libffi path cannot be seen, specify it.

export LDFLAGS="-L/usr/local/opt/libffi/lib" && \
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" && \
bundle install

Now there is no ffi installation error and the rails application has started!

Reference article