postmodern / ruby-install

Installs Ruby, JRuby, TruffleRuby, or mruby
MIT License
1.91k stars 255 forks source link

Apple Silicon Mac should require ARM64 homebrew #488

Closed anderium closed 1 month ago

anderium commented 1 month ago

Description

After having migrated from an Intel mac to Apple Silicon I had kept my previous homebrew install. Trying to install ruby failed because one of the library dependencies.

Steps To Reproduce

Steps to reproduce the bug:

  1. Install x86_64 homebrew on an Apple Silicon Mac.
  2. $ ruby-install ruby

Expected Behavior

Ruby can compile.

ruby-install warns the user that they have an emulated version of homebrew and that installing will likely fail. Directing the user to reinstall homebrew so that it runs natively. (E.g. https://blog.smittytone.net/2021/02/07/how-to-migrate-to-native-homebrew-on-an-m1-mac/)

Actual Behavior

Ruby does not compile for possibly multiple reasons:

  1. psych cannot find libyaml because it does not come in an arm64 version when using x86_64 homebrew
  2. libffi also was not found by the compiler automatically; it failed to compile closure.c. This can be fixed by exporting the env vars that brew info libffi gives.

Environment

$ brew config
HOMEBREW_VERSION: 4.3.18-42-g1bf48e2
[24 lines hidden]
Rosetta 2: true
$ ruby-install --version
ruby-install: 0.9.3
$ uname -a
Darwin MacBook-Pro 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030 arm64
$ cc --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ openssl version
OpenSSL 3.3.1 4 Jun 2024 (Library: OpenSSL 3.3.1 4 Jun 2024)

Solution

Reinstall homebrew natively by following the intructions here: https://brew.sh/#install. Recommended to also change $PATH and some other variables, see this blog post.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
havenwood commented 1 month ago

Toolchains can break in so many ways across various operating systems that even warning for common breakages becomes fractal. I'd consider this an upstream issue since Homebrew and brew doctor can get you on the right track but it's outside the scope of what ruby-install does as a tool.

For what it's worth, macOS disk migrations from Intel are already in steep decline and will fall off. That said, you might consider filing an upstream warning enhancement request with Homebrew. It's preferable for Homebrew to warn about how to fix itself rather than every brew tool each doing their own take downstream.

monfresh commented 1 month ago

I agree with @havenwood, and I would also add that simply having an Intel installation of Homebrew on an Apple Silicon Mac is not a sign that something is wrong. It is perfectly reasonable, and sometimes necessary, to have an Intel installation of Homebrew (which can also exist at the same time as an arm64 installation).

For example, if you're working on a legacy Ruby project that uses a Ruby version older than 2.6, and/or older versions of gems that don't work on arm64 (such as ffi < 1.15.2), then the only way to safely get the project running locally (aside from using Docker or something similar) is to have a proper Ruby dev environment using Rosetta.

Also, Homebrew already performs some of these checks. If your current environment is arm64, but the only Homebrew installation is in /usr/local, and if you run brew doctor, Homebrew will print out this warning:

Warning: Your Homebrew's prefix is not /opt/homebrew.

Many of Homebrew's bottles (binary packages) can only be used with the default prefix.
Consider uninstalling Homebrew and reinstalling into the default prefix.
anderium commented 1 month ago

Valid points! Thanks for the answers