2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M1 Macにhomebrewを再インストールする

Posted at

M1 Macで誤ってIntel Mac用のhomebrewをインストールしていたことに気づいたので、M1 Mac用のhomebrewをあらためてインストールした。

目次

  1. 実施環境
  2. 発生した問題
  3. 解決策

実施環境

  • 端末: MacBook Air M1, 2020
  • OS: Sequoia 15.0.1
  • 通信環境: UQ WiMax
  • Ruby: 3.3.6

発生した問題

rbenvでRuby 3.3.6をインストールしようとした際にエラーが出た。

$ rbenv install 3.3.6
...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
-> ./configure "--prefix=$HOME/.rbenv/versions/3.0.1" --with-openssl-dir=/opt/homebrew/opt/openssl@1.1 --enable-shared --with-readline-dir=/opt/homebrew/opt/readline --with-libyaml-dir=/opt/homebrew/opt/libyaml --with-ext=openssl,psych,+

BUILD FAILED (macOS 15.0 on arm64 using ruby-build 20240221)

解決策

調べたら下記のブログの状況(Intel Mac用のhomebrewをインストールしていた)が当てはまっていそうだった。

ブログの内容にしたがって下記を実施した。

インストールされているhomebrewがIntel Mac用かApple Silicon用か確認

brew --prefix

/opt/homebrew ならApple Silicon用。
/usr/local ならIntel Mac用。
/usr/local だったので Intel Mac用がインストールされていることが判明。

使用しているhomebrewがIntel Mac用かApple Silicon用か確認

which brew

/usr/local/bin/brewならIntel Mac用。
/opt/homebrew/bin/brewならApple Silicon用。
/usr/local/bin/brew だったので Intel Mac用を使用していることが判明。

現在のシステムのアーキテクチャを確認

uname -m

x86_64ならIntelプロセッサ。
arm64ならM1チップ(Apple Silicon用)。
arm64だったのでアーキテクチャはM1チップであることがわかった。

現在インストールされているパッケージをバックアップ

下記のコマンドで、インストールされているパッケージが~/.Brewfileに書き出される。

brew bundle dump --global

ホームディレクトリに.Brewfileができていることを確認。

ls ~/.Brewfile

Intel Mac用のhomebrewをアンインストール

下記コマンドでアンインストールし

export PATH=/usr/local/bin:${PATH}
brew uninstall $(brew list)

アンインストールできたか確認。

brew list

何も表示されなければOK。

Apple Silicon用のhomebrewをインストール

下記コマンドでhomebrewをインストール。

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

インストールできたか確認。

brew --prefix

/opt/homebrewと表示されればOK。

パスを通す

~/.zshrcに下記を追記。

export PATH="/opt/homebrew/bin:$PATH"

バックアップしたパッケージリストからパッケージをインストール

brew bundle --global

先ほど書き出した~/.Brewfileにリストされているパッケージが順次インストールされる。

以上でApple Silicon用homebrewがインストールできた。
この後再度rbenvでRuby 3.3.6のインストールを行ったところ、無事に成功した。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?