Some gems have issues installing on macOS. There is a list of possible solutions.
https://gist.github.com/fernandoaleman/ee3ac6957c2ba4f7d7d33a251d58b191
brew install openssl
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
brew link libffi --force
brew install v8-315
gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@3.15