Installing Ruby 3.0.x works fine on M1 MacBooks using rbenv
or asdf
. But older versions like 2.7.x and 2.6.x are having various issues. How do I fix them, without installing both x86 and ARM versions of homebrew
at the same time?
7 Answers
In order to make installing of Ruby versions 2.6.x or 2.7.x successful on M1 MacBook using either rbenv
or asdf
(asdf is used in this example) follow these steps:
Upgrade to the latest version of rbenv
or asdf-ruby
plugin using your prefered installation method. In my case it's asdf-ruby
installed over homebrew:
brew upgrade asdf
asdf plugin update ruby
Reinstall the current versions of openssl
, readline
and ruby-build
in order to have the latest versions and configs:
brew uninstall --ignore-dependencies readline
brew uninstall --ignore-dependencies openssl
brew uninstall --ignore-dependencies ruby-build
rm -rf /opt/homebrew/etc/openssl@1.1
brew install -s readline
brew install -s openssl
brew install -s ruby-build
In your shell config .bashrc
or .zshrc
add the following ENV variables:
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
export LDFLAGS="-L/opt/homebrew/opt/readline/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/readline/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig:$PKG_CONFIG_PATH"
export optflags="-Wno-error=implicit-function-declaration"
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
This will ensure that the proper libraries and headers are used during the installations and it will ignore the implicit-function-declaration
that is preventing some versions to continue installation. Note that for some other shells like fish
the exporting of these variables will be a bit different.
Now start a new terminal session and you can try installing the older ruby versions:
asdf install ruby 2.7.2
asdf install ruby 2.6.5
Note that really old versions below 2.5 might still have issues. Most of the credits go to this Github issue.
UPDATE
For Ruby 2.2 please change the following variable:
export RUBY_CONFIGURE_OPTS=openssl@1.0
And do a
asdf reshim ruby
Thanks @xjlin0 for this update

- 992
- 1
- 8
- 17
-
5I've a legacy project still creeping along with 2.4, and your recommendations worked in my testing. Thanks! – Yoopergeek Nov 29 '21 at 20:55
-
I should have mentioned it at the time as it could be helpful to others - I was using rbenv and it's ruby-build for my testing. – Yoopergeek Dec 08 '21 at 15:54
-
3i confirm it works with asdf but not rbenv did same steps – Almokhtar Jan 05 '22 at 18:01
-
Yeah, as I mentioned I did try it with asdf, I just assumed it should work with rbenv since asdf is using rbenv under the hood. And for @Yoopergeek it did work with rbenv ♂️ – orthodoX Jan 06 '22 at 09:07
-
5Uninstalling and reinstalling OpenSSL using these instructions jacked up my rubygems and npm registry fuctionality, and I had to manually install CA certs. – yuяi Jan 11 '22 at 04:03
-
1Actually, still having issues in various places. For example: `Warning UNABLE_TO_GET_ISSUER_CERT_LOCALLY: request to https://registry.npmjs.org/yarn failed, reason: unable to get local issuer certificate ` – yuяi Jan 11 '22 at 12:12
-
2for 2.2 https://github.com/rbenv/ruby-build/issues/1742#issuecomment-835790760 plus set RUBY_CONFIGURE_OPTS to openssl@1.0 and `asdf reshim ruby` – xjlin0 Jan 21 '22 at 16:55
-
@xjlin0 I've updated the post with your info. Thanks! – orthodoX Jan 22 '22 at 22:07
-
1What is `libffi`? As far as I know you need to export `/opt/homebrew/opt/readline` and `opt/homebrew/opt/openssl@3` eg.: `export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)"`, `export LDFLAGS="-L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/openssl@3/lib"`, `export CPPFLAGS="-I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/openssl@3/include"`, `export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig /opt/homebrew/opt/openssl@3/pkgconfig"` [code] – Marcelo Xavier Mar 15 '22 at 14:04
-
@MarceloXavier libffi is a C foreign function interface library. As far as I remember without this setting my installers were not passing successfully. – orthodoX Mar 16 '22 at 15:34
-
@orthodoX asdf *does not* use rbenv under the hood, it uses ruby-build. Both projects are hosted by the rbenv org on Github, but they are not the same. rbenv is a ruby version manager, the same function as asdf. rbenv also uses ruby-build under the hood. – Peter H. Boling Jun 10 '22 at 14:29
-
I have rosetta installed, so with `arm64` doesn't worked. ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/mberrueta/.zprofile eval "$(/usr/local/bin/brew shellenv)" arch -x86_64 brew install asdf asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git asdf plugin update ruby arch -x86_64 brew install -s readline arch -x86_64 brew install -s openssl arch -x86_64 brew install -s ruby-build asdf install ruby 2.6.9 ``` – Math Jun 28 '22 at 01:10
-
Please be careful suggesting this type of forced install with "ignore" flags, this is dangerous and may screw up another tool that requires this dependencies; KEEP THIS IN MIND if you use this answer!!! – Stoic Alchemist Aug 12 '22 at 11:35
-
3This does not work on BUILD FAILED (macOS 12.6 using ruby-build 20220910.1) – julio Sep 24 '22 at 06:06
-
1This doesn't work anymore on macOS 12.6 – Oleksandr Danylchenko Oct 09 '22 at 14:48
-
not working for me on Mac OS 12.5.1 – johnsimer Nov 14 '22 at 15:03
-
A similar comment than the one for ruby <= 2.2.x should appear for ruby versions above 3.0.0, the recommended openssl version in that case is openssl@3 – halbano May 29 '23 at 16:56
This simple command helped me
RUBY_CFLAGS="-w" rbenv install 2.5.5

- 351
- 3
- 6
-
2wow this really works as of january 23 unlike accepted version which is also much more work – Joe Half Face Jan 23 '23 at 10:34
Faced with an error on M2 Pro, Ventura 13.4.1
Error running '__rvm_make -j12',
please read /Users/mkrasikov/.rvm/log/1688468004_ruby-2.7.4/make.log
There has been an error while running make. Halting the installation.
Solved with:
brew install rbenv
RUBY_CFLAGS="-w" rbenv install 2.7.4

- 33
- 4
I have faced the same issue for Ruby 2.2.2 and many gems were dependent on that. So I have created a docker container for ubuntu 18.04 and then installed ruby on it. It's working.

- 154
- 5
-
Yes, I prefer to have my development setup dockerized for all the projects as well. But I do have the languages I work with installed locally for the sake of linting and formatting used by the editors. It's doable to use lint/format from within the containers themselves but the experience is still not that great and easy to set up for a lot of editors. That's why I keep just Ruby/Elixir versions installed locally, but all other services I use strictly from Docker, like Posgres, Redis, etc. – orthodoX Jan 31 '22 at 10:26
For OSX v12.6.1 with frum on M1 Macbook Pro 2021 I used the following exports in ~/.bash_profile after installing ruby-build with brew to successfully build ruby 2.6.5
export optflags="-Wno-error=implicit-function-declaration"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)"
export LDFLAGS="-L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/openssl@3/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig /opt/homebrew/opt/openssl@3/pkgconfig"

- 583
- 9
- 15
This issue has been resolved for ruby 2.7.10 and onward. If you're using a version manager, such as asdf, this should be resolved for the full 2.7.x version range (not just 2.7.10).
The underlying issue is an incompatibility introduced in Xcode 14. One solution is to downgrade to Xcode 13, so that you can build ruby. This isn't a viable path for many users, so another option is to get an already built version of ruby for your architecture, which occurs with downloads from homebrew
.
Homebrew has a formulae for ruby@2.6 that will run on MacOS M1 (arm) and older intel based models (x86). You can install this with
brew install ruby@2.6
which will install ruby 2.6.10. If that's all you need, you can stop here.
If you want to use ruby 2.6 with a version manager such as asdf
, you can do the following:
brew install ruby@2.6
ln -s $(brew --prefix ruby@2.6) ~/.asdf/installs/ruby/2.6.10
asdf reshim ruby 2.6.10

- 4,236
- 1
- 26
- 22
thanks to @orthodox
with rosetta I has brew under arm64. so I uninstall it, and reinstall with x86 and worked
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/mberrueta/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
arch -x86_64 brew uninstall --ignore-dependencies asdf
arch -x86_64 brew install asdf
arch -x86_64 brew upgrade asdf
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
asdf plugin update ruby
arch -x86_64 brew uninstall --ignore-dependencies --force openssl
arch -x86_64 brew uninstall --ignore-dependencies --force ruby-build
rm -rf /opt/homebrew/etc/openssl@1.1
arch -x86_64 brew install -s readline
arch -x86_64 brew install -s openssl
arch -x86_64 brew install -s ruby-build
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
export LDFLAGS="-L/opt/homebrew/opt/readline/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/readline/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig:$PKG_CONFIG_PATH"
export optflags="-Wno-error=implicit-function-declaration"
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
asdf install ruby 2.6.9

- 768
- 1
- 8
- 18