LoginSignup
3
2

M1MACProにHomebrewのインストールでつまづいた

Last updated at Posted at 2023-11-06

Homebrewとは

Macのバージョンを上げるとPythonが消えていた!? という事態になってしまったため、どうしたもんか......と調べたところパッケージツールをインストールしてみようというところでHomebrewを選択しました。
HomebrewはMacOS環境ではスタンダードなパッケージマネージャーです。
今回はHomebrewをインストールするにあたり、躓いたことを忘備録として残します。

HomebrewはMac環境のみで起動するわけではないです。Windowsでも起動可能となります。

Hombrewインストール

まずHomebrewをインストールするために公式HPを表示します。
自分のOSにパッケージ名があっているか確認してください。
今回はMacOS用のパッケージマネージャーの記載があるHPからインストール用のPATHを取得します。

スクリーンショット 2023-10-28 8.37.30.png
インストールの下にあるコマンドを右にあるファイルマークをクリックしてコピーして、ターミナルにて実行します。

 HEAD is now at f89c7194e Merge pull request #16098 from 
 reitermarkus/odebug-system-command
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/ユーザ名/.bash_profile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh`

ユーザ=Macに設定されているユーザ名が入ります。

途中で「Warning」が表示されていますが、「Next Steps:」と実施する手順が表示されているので、その通りに実施しましょう。
今回は以下を実施します。

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/ユーザ名/.bash_profile

実施ユーザによっては権限がないため、「sudo」を頭につけて実行するか、rootユーザに変更して実行してください。

では正常に完了しているかどうか確認しましょう。

MacBook:bin $ brew -v
/usr/local/Homebrew/Library/Homebrew/brew.sh: line 662: /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/current/bin/ruby: Bad CPU type in executable
/usr/local/Homebrew/Library/Homebrew/brew.sh: line 662: /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/current/bin/ruby: Undefined error: 0

rubyのフォルダのようですが......そもそも「CPU type」がBADと出ていますね。
M1版を入れてるけどIntel版で認識されたのだろうか......
と調べてみるとRossetaをインストール必要があるよとのこと......
いや、Rosettaを入れなくてもいけるとの情報はあるぞ......
と探しても解決にならず......
白旗:dash:をあげて、結局アンインストールすることにしました。

Homebrewのアンインストール

GitHubのページにアクセスして、アンインストール実行PATHをコピーします。
GitHubページ
赤枠にあるPATHをコピーしてください。
スクリーンショット 2023-10-30 12.30.50.png

では実行。

Warning: This script will remove:
/Users/ユーザ/Library/Caches/Homebrew/
/opt/homebrew/.devcontainer/
[省略]
/opt/homebrew/package/
Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] y
==> Removing Homebrew installation.
==> Removing empty directories.
Password:

This will remove your installed packages! [y/N]」のコメント後に「y」を選択し、root権限のパスワードを求められるので入力します。

基本的にはログインする時のパスワードです。

uninstalled!」が出ましたら成功!! ただし「not deleted」があるよと出ました。
You may wish to remove them yourself.」とあり、
いろんな権限あるものだから自分で消してねとのこと。
Homebrewの内容のみだったので自分は全消ししました。

==> Homebrew uninstalled!
The following possible Homebrew files were not deleted:
/opt/homebrew/etc/
/opt/homebrew/share/
/opt/homebrew/var/
You may wish to remove them yourself.

Homebrew再インストール

というわけで気を取り直して再インストール。
手順は一緒。

HEAD is now at ce63b7c7f Merge pull request #16144 from Bo98/pr-upload-gem-fix
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 this command in your terminal to add Homebrew to your PATH:
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

実行結果もほぼ一緒やなぁと眺めていると......おや「Next steps:」の記載がちょっと違いますね。
表示通りに実行をします。

eval "$(/opt/homebrew/bin/brew shellenv)"

上記コマンドを実行すると......

yuunoMacBook$ brew -v
Homebrew 4.1.17

あれ? 行けてんやん......なんで何???
さっきまでの手こずり方は一体?? というほどPATHが通りました。

というわけで、原因は不明ですが、アンインストール→インストールを実施すると完了しました。

長い道のりでしたが......なんとかなりました。

参考

こちらのHPを参考にさせていただきました。

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