The problem with installing older Ruby versions, is that OpenSSL, a dependency of older Ruby versions, is "end of life" and not shipped using brew anymore. Later versions of OpenSSL are not compatible.

The only way to install older Ruby versions now, is to patch OpenSSL locally.

Pre-Requisite

It's very important, that you make sure, that the whole dependency chain has been installed using the same Terminal. That means, if you install homebrew via a Rosetta Terminal, and then openssl/Ruby using an arm64 Terminal, then you need to completely uninstall everything, and start over. This guide has been tested with an arm64 Terminal. Make sure to NOT start the Terminal using Rosetta.

If you find packages like Ruby in /usr/ (Intel), but brew and openssl in /opt/ (arm64), then reinstall it using the Terminal you installed it with.

Start a Rosetta Terminal to deinstall everything from /usr/ and start an arm64 Terminal to delete everything from /opt/

  • delete Ruby
  • delete openssl
  • delete Homebrew
  • install Homebrew

Make sure, that everything is now installed in /opt/ (arm64),
and not /usr/ (Intel)

Install openSSL

  • To easily download the file, open the article you're reading in Safari
  • Right click this link and select "Download Linked File As"
  • Save as "openssl@1.0.rb" in "Downloads"
  • In Terminal, run: brew install ~/Downloads/openssl@1.0.rb to install this patched OpenSSL 1.0 version
  • Run the following in Terminal to add openssl to your PATH.
echo 'export PATH="/opt/homebrew/opt/openssl@1.0/bin:$PATH"' >> ~/.zshrc
  • Add the following exports to your zshrc:
# OpenSSL
export PATH="/opt/homebrew/opt/openssl@1.0/bin:$PATH"

# For compilers to find openssl@1.0 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.0/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.0/include"
export RUBY_CFLAGS="-DUSE_FFI_CLOSURE_ALLOC"
  • Reload your shell, in Terminal run: source ~/.zshrc
  • Verify your OpenSSL version:
openssl version
OpenSSL 1.0.2u  20 Dec 2019
  • Install Ruby using your preferred method, f.e.:
RUBY_CONFIGURE_OPTS=--with-openssl-dir=/opt/homebrew/opt/openssl@1.0 ruby-build 2.3.8 ~/.runtimes/Ruby23x  

This guide should help you to install the Core of OpenSSL 1.0 and Ruby 2x.

If you found this article helpful, please consider sharing it on Twitter and Reddit. It genuinely helps people to unblock themselves and might safe someone a day of frustration.