After lots of trial and error, I finally got ruby 2.7.6 installed on my early mac m1 (macOS 12.6).
There are many blog posts out there suggesting different flags, ignoring warnings etc. But in the end, this is what worked for me.
DO NOT use the brew / ibrew setup, where ibrew is aliased to arch -x86_64 /usr/local/bin/brew
.
It will mess up your system with conflicting packages and paths.
Use a terminal without Rosetta 2.
Uninstall x86_64 homebrew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Reinstall arm64 homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(maybe reinstall some packages like brew reinstall gdbm readline [email protected] libffi libyaml
Then add these (as suggested by homebrew after installing) to your shell rc (~/.zshrc
)
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix [email protected]` --with-readline-dir=`brew --prefix readline`"
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 LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig:$PKG_CONFIG_PATH"
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"
Don't try to use openssl@3, it won't work.
I use asdf version manager, but you can use rbenv too, they both use ruby-build.
brew install asdf
asdf plugin add ruby
asdf install ruby 2.7.6
If compiling doesn't work, try using an older version of xcode commandline tools. (as suggested here)
The most common error I encountered was this one
The beginning of the log started with
which made me frown, because it's supposed to be
I also tried passing build flags for these, which got me a step further, but no sigar.
Finally I figured that it was the whole ibrew setup that got things mixed up.