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

# 概要
MacでHomebrewをインストールし
brewコマンドのパスを通す

💻 [Homebrew公式サイト](https://brew.sh/index_ja)

# 手順
1.ターミナルを開く

2.下記のコマンドを実行

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

3.パスワードを入力します

```bash
==> Checking for `sudo` access (which may request your password)...
Password:
```

インストールが実行されていきます

```bash
==> 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
```

4.指示に従いEnterキーを押します。

```bash
Press RETURN to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R (username):admin /opt/homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 1221, done.
remote: Counting objects: 100% (664/664), done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 1221 (delta 578), reused 638 (delta 560), pack-reused 557
Receiving objects: 100% (1221/1221), 363.62 KiB | 1.10 MiB/s, done.
Resolving deltas: 100% (789/789), completed with 113 local objects.
From https://github.com/Homebrew/brew
 * [new branch]          dependabot/bundler/Library/Homebrew/sorbet-0.5.9566 -> origin/dependabot/bundler/Library/Homebrew/sorbet-0.5.9566
   385892f3d..05b5a2c49  master     -> origin/master
 * [new tag]             3.3.10     -> 3.3.10
 * [new tag]             3.3.11     -> 3.3.11
 * [new tag]             3.3.12     -> 3.3.12
HEAD is now at 05b5a2c49 Merge pull request #12793 from Homebrew/dependabot/bundler/Library/Homebrew/rbi-0.0.10

Updated 1 tap (homebrew/core).
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/(username)/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh
```

5.下記を実行

```bash
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/(username)/.zprofile
```
(username)の箇所は、お使いのPCに応じて変換してください
コピーするコマンドは、手順4の最後の方に
"Run these two commands in your terminal to add Homebrew to your PATH:"
の下にあるコマンドをコピーして実行してください

6.下記を実行

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

# 最後に
手順の5、6の補足です
4のコマンド実行時の最後に

```bash
Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
```
上記が出力されています。
「次のステップとして、
ターミナルで2つのコマンドを実行して、HomebrewをPATHに追加する」
という意味なので、
手順5、6を実行してbrewコマンドのPATHを通しています。

下記を実行してインストールされていることを確認します

```bash
(username)noMacBook-Air ~ % brew -v
Homebrew 3.3.12
Homebrew/homebrew-core (git revision a0e81be5dbf; last commit 2022-01-28)
```

# 参考サイト
https://lanchesters.site/brew-commnad-not-found/#path

---
# Overview
Installing Homebrew on Mac and adding the brew command to the PATH.

↓Official Homebrew Website  
[Homebrew](https://brew.sh/index_ja)  
[Homebrew (Japanese)](https://brew.sh/index_ja)

# Steps
1. Open Terminal

2. Run the following command:

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

3. Enter your password when prompted:

```bash
==> Checking for `sudo` access (which may request your password)...
Password:
```

The installation will start running:

```bash
==> 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
```

4. Press Enter to continue as instructed:

```bash
Press RETURN to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R (username):admin /opt/homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 1221, done.
remote: Counting objects: 100% (664/664), done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 1221 (delta 578), reused 638 (delta 560), pack-reused 557
Receiving objects: 100% (1221/1221), 363.62 KiB | 1.10 MiB/s, done.
Resolving deltas: 100% (789/789), completed with 113 local objects.
From https://github.com/Homebrew/brew
 * [new branch]          dependabot/bundler/Library/Homebrew/sorbet-0.5.9566 -> origin/dependabot/bundler/Library/Homebrew/sorbet-0.5.9566
   385892f3d..05b5a2c49  master     -> origin/master
 * [new tag]             3.3.10     -> 3.3.10
 * [new tag]             3.3.11     -> 3.3.11
 * [new tag]             3.3.12     -> 3.3.12
HEAD is now at 05b5a2c49 Merge pull request #12793 from Homebrew/dependabot/bundler/Library/Homebrew/rbi-0.0.10

Updated 1 tap (homebrew/core).
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!
```

5. Follow the instructions to add Homebrew to your PATH by running the following command (replace `(username)` with your actual username):

```bash
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/(username)/.zprofile
```

This command can be found at the end of the output from step 4 under the "Next steps" section.

6. Run the next command:

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

# Final Steps
As a recap of steps 5 and 6, the following output is displayed during step 4:

```bash
Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
```

This means you need to run steps 5 and 6 to add the brew command to your PATH.

Finally, check that Homebrew is installed by running the following:

```bash
(username)noMacBook-Air ~ % brew -v
Homebrew 3.3.12
Homebrew/homebrew-core (git revision a0e81be5dbf; last commit 2022-01-28)
```

# Reference Site
[How to fix 'brew command not found' issue](https://lanchesters.site/brew-commnad-not-found/#path)