Alexander Ross

⏱ around 2 minutes read time

Tagged with:

Install ruby 2.1 on macOS Big Sur

Installing ruby 2.1 on macOS Big Sur may be cumbersome. You should probably not use 2.1 for new projects but if you like me you may have an old project around that needs an upgrade. And testing in the old ruby version the project was written for first is not a bad start.

However when I tried to install the Ruby 2.1.10 for the project I got a lot of compilation errors and Google suggested a lot of solutions for me that did not work. But a combination of them did. So here is a TLDR version of the solution that did work for me.

Install OpenSSL 1.0 with Homebrew. This can live side by side with the latest version of OpenSSL available in Homebrew.

brew install rbenv/tap/[email protected]

Install Ruby 2.1.10 using asdf with some additional compiler configurations.

PKG_CONFIG_PATH="$(brew --prefix [email protected])/lib/pkgconfig" \
LDFLAGS="-L$(brew --prefix [email protected])/lib" \
CPPFLAGS="-I$(brew --prefix [email protected])/include" \
PATH="$(brew --prefix [email protected])/bin:$PATH" \
CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" \
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected]) --with-readline-dir=$(brew --prefix readline)" \
optflags="-Wno-error=implicit-function-declaration" \
asdf install ruby 2.1.10

asdf is using ruby-build behind the scene. So do most rbenv installations as well. So if you use rbenv you should be able to replace the last part asdf install ruby 2.1.10 with rbenv install 2.1.10.

Tagged with: