Parallels Desktop 20%OFFセール中Check!

M1 MacにHomebrewをインストールする方法

Homebrewをインストールする方法

MacをUNIX/Linuxっぽく使うときの必須ツールHomebrewのインストール方法を解説します。

環境
  • Mac mini (M1, 2020)
  • macOS Monterey
目次

Homebrewとは

Homebrewとは、macOS(やLinux)のためのパッケージ管理システムです。ここで言うパッケージとは、ソフトウェアの実行ファイル、ライブラリ、設定ファイルなどをまとめたものですね。パッケージのインストールやアンインストール、依存関係などを管理するのがパッケージ管理システムです。

Command Line Tools for Xcodeのインストール

HomebrewをインストールするにはCommand Line Tools for Xcodeというモノが必要になるので、まずはこれをインストールします。これが一体何なのか。聞かないでください。

ターミナルで次のコマンドを入力してReturn

xcode-select --install

次のようなポップアップが出るので「インストール」を押します。

CTLインストールのポップアップ

ちょっと時間がかかります。20分くらいで終わるでしょうか。

Homebrewのインストール

公式サイトのトップにでーんと書いてあるコマンドでインストールすることができます。ターミナルを起動してこのコマンドを実行しましょう。

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

インストールコマンドは変更されるかもしれないので、公式サイトからコピペしてくださいね。

インストールコマンドの実行

ターミナルでコマンドを実行します。

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:

パスワードの入力を求められるので、Macの管理者パスワードを入力してReturn

==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks

Press RETURN to continue or any other key to abort:

このスクリプトは下記のものをインストールしますよ、下記のディレクトリを作成しますよという確認が表示されます。そして、Returnキーで続行、その他のキーで中止だそうです。Returnキー押しちゃう?

==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew

(中略)

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 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/********/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

/opt/homebrew/bin にPATHが通ってないよ」という警告がでます。これは後で設定します。そして「Installation successful!」とありますので、無事にインストールは成功しました。いえい。

PATHを通す

PATHが通っていないよという警告があり、PATHを通すためのコマンドも教えてくれているので(やさしい)、その通りにします。

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

動作確認

brew -vを実行してバージョン情報が表示されたらOKです。

% brew -v
Homebrew 3.4.1
Homebrew/homebrew-core (git revision 9b5641b3314; last commit 2022-03-13)

Homebrewのアンインストール

ついでに、アンインストールの方法です。アンインストールコマンドはここにあります。

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Warning: This script will remove:
(中略)
Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] y

削除されるファイル、ディレクトリの一覧が表示され、本当にアンインストールしていいのかえ?インストールしてたパッケージも削除されるで!と言われるので、yと入力してReturnします。

==> Removing Homebrew installation...
Warning: Failed to delete /opt/homebrew/Cellar
(中略)
==> Removing empty directories...
Password:

削除できないファイルがあるよという警告が出ることがあります。あとで手動で削除しましょう。パスワードの入力を求められるので、Macの管理者パスワードを入力してReturnします。

==> /usr/bin/sudo /usr/bin/find /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/opt /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/Cellar /opt/homebrew/Frameworks -name .DS_Store -delete
==> /usr/bin/sudo /usr/bin/find /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/opt /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/Cellar /opt/homebrew/Frameworks -depth -type d -empty -exec rmdir {} ;
==> Homebrew uninstalled!
The following possible Homebrew files were not deleted:
/opt/homebrew/Cellar/
/opt/homebrew/Frameworks/
/opt/homebrew/SECURITY.md
/opt/homebrew/bin/
/opt/homebrew/etc/
/opt/homebrew/include/
/opt/homebrew/lib/
/opt/homebrew/opt/
/opt/homebrew/sbin/
/opt/homebrew/share/
/opt/homebrew/var/
You may wish to remove them yourself.

「Homebrew uninstalled!」とありますので、無事にアンインストールは成功しました。いえい。

削除できなかったファイルがあるので、ディレクトリ homebrewごと削除しちゃいましょう。というか、Homebrew関連のファイルはすべてここに集まってるので、最初からこのディレクトリを削除でもよさそうですね。

rm -rf /opt/homebrew

以上です。

でわでわ

Homebrewをインストールする方法

この記事が気に入ったら
いいね または フォローしてね!

シェアしてね

コメント

コメントする

目次