7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Mac】 Intel Sillicon→Apple SilliconにHome brewを変更する方法

Posted at

こんにちは、たけるです^^。
久しぶりの投稿になります。

先日、念願のApple SilliconのMacBook Proを購入いたしました!
もちろん、Homebrewも変更しないといけなくなる認識はあったのです。

まず、移行アシスタントで移行すると、Intel Silliconの環境がApple Silliconに移りました。
その際、Homebrew(/usr/local以下)も無事に移行されました。
その際に、私はてっきりhome updateからのhome upgradeで解決すると思い込んでいました。。。
が、Apple Silliconの場合は管理ディレクトリが/usr/local/から/opt/local/に変わるとのことで。。。
そりゃそうですよね^^;。

そこで、今回は、Intel Silliconの時に使用していた環境を移した状態でHomebrewをreinstallする方法について記載したいと思います。

すでにInstallしているFomulaの確認

もし、すでにインストールしているFomulaをそのまま次の環境でもインストールしたい場合、これらをインストールする必要があります。
その場合は現在Install済みのFomulaを確認する必要があります。

以下のコマンドで確認してください。

% brew list

ここで出てきたリストを記憶してください。
もし必要であれば、リダイレクションを活用してファイルに出力して下さい。

% brew list > ~/brew_list_2023xxxx.txt

また、Serviceなどを動かしていて、次の環境でも同じように動かしたい場合は、
以下の方法でファイルに保存する等してください。

% cd /usr/local; tar cvzf ~/usr_local_etc_2023xxxx.tgz ./

Uninstall

いよいよアンインストールします。
以下のコマンドを実行します。

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

すると、順番にアンインストールしてくれますが、最後に以下のようなメッセージが出ました。

Warning: Failed during: /usr/bin/sudo rmdir /usr/local
Warning: Homebrew partially uninstalled (but there were steps that failed)!
To finish uninstalling rerun this script with `sudo`.
The following possible Homebrew files were not deleted:
/usr/local/.com.apple.installer.keep
/usr/local/Frameworks/
/usr/local/Homebrew/
/usr/local/bin/
/usr/local/cuda/
/usr/local/etc/
/usr/local/include/
/usr/local/lib/
/usr/local/lmm/
/usr/local/opt/
/usr/local/remotedesktop/
/usr/local/sbin/
/usr/local/share/
/usr/local/var/
You may wish to remove them yourself.

まだディレクトリは完全に消えていないようですが、とりあえずこれでhomebrewを削除できたようです。
中身を調べて上記のディレクトリを順番に消しても良いのですが、Apple Sillicon版のHomebrewは/opt/homebrewに入ることを考えるとすぐ消さなくても害はないと判断し、すぐインストールに入りました。

Install (Apple Sillicon Version)

インストールは以下のコマンドを実行します。

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

これはuninstallの時と同様、スクリプトを実行しているので、必要なデータのダウンロードからインストールまでを実行してくれます。
途中でディレクトリの権限変更やxcodeのcommand line toolをインストールするためにログインパスワードを訊かれたりします。

最後に次のメッセージが出ます。

HEAD is now at 853b33bcd Merge pull request #14742 from apainintheneck/respect-quiet-with-api-downloads
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/takeru/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

Installation successful!と書かれていれば、インストールは成功しているでしょう。
しかし、PATHは通っていないとも書いていますね。

Next stepsに書かれている通り、次のコマンドを実行しましょう。

% (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/takeru/.zprofile
% eval "$(/opt/homebrew/bin/brew shellenv)"

これでPATHにも通ったはずです。次のコマンドで確認しましょう。

% which brew
/opt/homebrew/bin/brew

brewコマンドの場所が/opt/homebrew配下になっていますね。

次のコマンドを実行して返答があれば成功です。

% brew help
Example usage:
  brew search TEXT|/REGEX/
  brew info [FORMULA|CASK...]
  brew install FORMULA|CASK...
  brew update
  brew upgrade [FORMULA|CASK...]
  brew uninstall FORMULA|CASK...
  brew list [FORMULA|CASK...]

Troubleshooting:
  brew config
  brew doctor
  brew install --verbose --debug FORMULA|CASK

Contributing:
  brew create URL [--no-fetch]
  brew edit [FORMULA|CASK...]

Further help:
  brew commands
  brew help [COMMAND]
  man brew
  https://docs.brew.sh

念の為、brew doctorの結果も確認しましょう。

% brew doctor
Your system is ready to brew.

さいごに

いかがでしたか?
今回は簡単にアンインストールからインストールまでを説明しましたが、これらはスクリプトで動かします。
ということは、どうやら実行時のオプションがいくつか存在するようです。
もし気になる方は、参考文献のリンクから色々調べてみてくださいね。

では、あなたも素敵なMacライフを^^!

参考文献

GitHUB - Homebrew/install

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?