Skip to content

Instantly share code, notes, and snippets.

@delneet
Last active October 24, 2022 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delneet/9d1e8f3a9f9735ade143673511a14e4b to your computer and use it in GitHub Desktop.
Save delneet/9d1e8f3a9f9735ade143673511a14e4b to your computer and use it in GitHub Desktop.
Install ruby 2.7.6 on a (early) Mac M1 with apple silicon chip

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 openssl@1.1 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 openssl@1.1` --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/openssl@1.1/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/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)

@delneet
Copy link
Author

delneet commented Oct 24, 2022

The most common error I encountered was this one

readline.c:1904:37: error: use of undeclared identifier 'username_completion_function'; did you mean 'rl_username_completion_function'?
                                    rl_username_completion_function);

The beginning of the log started with

checking build system type... x86_64-apple-darwin21.6.0
checking host system type... x86_64-apple-darwin21.6.0
checking target system type... x86_64-apple-darwin21.6.0

which made me frown, because it's supposed to be

checking build system type... aarch64-apple-darwin21.6.0
checking host system type... aarch64-apple-darwin21.6.0
checking target system type... aarch64-apple-darwin21.6.0

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment