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?
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/[email protected]
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 [email protected])"
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 [email protected]
And do a
asdf reshim ruby
Thanks @xjlin0 for this update
Warning UNABLE_TO_GET_ISSUER_CERT_LOCALLY: request to https://registry.npmjs.org/yarn failed, reason: unable to get local issuer certificate
β
Adeliaadelice asdf reshim ruby
β
Pellicle 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] β
Rangel arm64
doesn't worked. ``` /bin/bash -c "$(curl -fsSL 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 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 ``` β
Inexertion export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" 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"
β
Backwoodsman This simple command helped me
RUBY_CFLAGS="-w" rbenv install 2.5.5
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
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"
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.
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 [email protected] that will run on MacOS M1 (arm) and older intel based models (x86). You can install this with
brew install [email protected]
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 [email protected]
ln -s $(brew --prefix [email protected]) ~/.asdf/installs/ruby/2.6.10
asdf reshim ruby 2.6.10
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/[email protected]
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 [email protected])"
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
© 2022 - 2024 β McMap. All rights reserved.