Rails env setup, Apple Silicon (M1) troubleshooting

9:51 PM June 19 2021 devops

I was setting up my dev environment for a rails 5 app that runs with ruby 2.4.x and a good mix of gems.

The gems ffi, pg, mysql2, mimemagic and sassc needed some extra steps besides the regular bundle install, here's what I did:

Postgres

Use brew to install postgres, its actually easier than using Postgres.app

ffi 1.9.18

  • brew install libffi
  • type this in a terminal to set them as env variables export LDFLAGS="-L/opt/homebrew/opt/libffi/lib" export CPPFLAGS="-I/opt/homebrew/opt/libffi/include" export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
  • run the install with this cflags gem install ffi -v '1.9.18' -- --with-cflags="-Wno-error=implicit-function-declaration"

mysql2

  • Install mysql, openssl and zstd
  • brew install mysql
  • brew install openssl
  • brew install zstd

Then use this flags on the gem installation:
\
gem install mysql2 -v '0.5.2' -- --with-opt-dir="$(brew --prefix openssl)" --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib

If you need the path for zstd lib because its different than mine, you can find it like this
ls -la $(which zstd)

mimemagic

 brew install shared-mime-info
 gem install mimemagic -v '0.3.10'

sassc

In this case I just updated the gem because they solved the issue in newer versions.
bundle update sassc
It installed without issues using v2.4.0

miniracer

While trying to run rake tasks, mini_racer throw some errors.:

dyld: lazy symbol binding failed: Symbol not found: __ZN2v82V813InitializeICUEPKc  Referenced from: /Users/<user>/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mini_racer-0.2.6/lib/mini_racer_extension.bundle

They addressed those issues on newer versions, so again, just updating the gem does the trick:\
bundle update mini_racer