LoginSignup
0
0

More than 1 year has passed since last update.

M1 Mac (macOS Monterey) で Ruby のインストールに失敗するときの対処法

Last updated at Posted at 2022-09-22

解決方法

M1 Mac で従来どおりに Ruby をインストールしようとするとビルドエラーが出てしまいます。

筆者の環境では以下のコマンドを実行することにより無事インストールすることができました。

まず、必要なパッケージをインストールします。

Shell
brew install openssl@1.1 readline libyaml

次に必要な環境変数をセットします。

shell
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
export LDFLAGS="-L/opt/homebrew/opt/readline/lib"
export CPPFLAGS="-I/opt/homebrew/opt/readline/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig"
export optflags="-Wno-error=implicit-function-declaration"
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
export RUBY_CFLAGS="-w"

これでインストールできるようになるはずです。

Shell
asdf install ruby <RUBY_VERSION>

上記の例では asdf を使用していますが、rbenv などでも同様にインストールできるようになると思います。

環境変数をエクスポートする代わりに実行時に指定することも可能です。

Shell
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" LDFLAGS="-L/opt/homebrew/opt/readline/lib" CPPFLAGS="-I/opt/homebrew/opt/readline/include" PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig" optflags="-Wno-error=implicit-function-declaration" LDFLAGS="-L/opt/homebrew/opt/libffi/lib" CPPFLAGS="-I/opt/homebrew/opt/libffi/include" PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig" RUBY_CFLAGS="-w" asdf install ruby <RUBY_VERSION>

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0