1
0

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.

Linux(Debian)にHomebrewをインストールする

Last updated at Posted at 2024-02-01

GCPで作成したVMインスタンスを弄るのに、まずはHomebrewをインストールしたときのメモ。

作業環境

・GCP Compute Engineで作成したVMインスタンス
・OS Debian 5.10.205-2
・デスクトップ環境はないのでCLIで操作
・Macからターミナルにてアクセス
事前にターミナルからインスタンスにアクセスしておきます

1. Homebrewをインストール

定番のHomebewのWebページにアクセス。
例に倣ってスクリプトをコピーします。
スクリーンショット 2024-02-01 16.45.38.png
コピーしたらターミナルに貼り付けて実行しましょう。

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

スクリプトがインストールするものが表示されます。

==> Checking for `sudo` access (which may request your password)...
==> This script will install:
/home/linuxbrew/.linuxbrew/bin/brew
/home/linuxbrew/.linuxbrew/share/doc/homebrew
/home/linuxbrew/.linuxbrew/share/man/man1/brew.1
/home/linuxbrew/.linuxbrew/share/zsh/site-functions/_brew
/home/linuxbrew/.linuxbrew/etc/bash_completion.d/brew
/home/linuxbrew/.linuxbrew/Homebrew

Press RETURN/ENTER to continue or any other key to abort:

Enterキーを押して進めようとすると...

==> /usr/bin/sudo /bin/chown -R yosuke:yosuke /home/linuxbrew/.linuxbrew/Homebrew
  You must install Git before installing Homebrew. See:
    https://docs.brew.sh/Installation

先にGitをインストールすべきだよ、と...

ということでGitをインストールしてみましょう。

2. Gitのインストール

aptコマンドでバージョン管理システムのGitをインストールします。

$ sudo apt -y install git

管理者権限が必要なので、sudoをつけるのを忘れずに。

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
~~~~(省略)~~~
Unpacking patch (2.7.6-7) ...
Setting up perl-modules-5.32 (5.32.1-4+deb11u2) ...
Setting up patch (2.7.6-7) ...
Setting up libgdbm-compat4:amd64 (1.19-2) ...
Setting up libperl5.32:amd64 (5.32.1-4+deb11u2) ...
Setting up git-man (1:2.30.2-1+deb11u2) ...
Setting up perl (5.32.1-4+deb11u2) ...
Setting up liberror-perl (0.17029-1) ...
Setting up git (1:2.30.2-1+deb11u2) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+deb11u7) ...

入力待ち状態に戻ればインストール完了です。
下記コマンドを実行してバージョンが表示されればOK

$ git --version
git version 2.30.2

3. 改めてHomebrewをインストール

それでは気を取り直してHomebrewのスクリプトを実行します
1.と同じように進んでいきますが、Enterを押したあともインストールが進んでいくと思います。

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /bin/chown -R yosuke:yosuke /home/linuxbrew/.linuxbrew/Homebrew
==> Downloading and installing Homebrew...

あとはインストールが終わるのを待ちましょう。
Install successful!
が表示されたのち、入力待ち状態に戻ればインストール完了です。

4. PATHを通す

インストール完了前に Warning: も表示されますが、上記通りにインストールしていればHomebrewは
/home/linuxbrew/ 以下にインストールされ、ここにはPATHが通っていません。
毎回/home/linuxbrew/.linuxbrew/binを入力するのも面倒なのでPATHを通してあげます。

現状のPATHは

$ echo $PATH

で確認できます。
printenvコマンドでも確認できますが、他の情報も色々と出てきてしまうので、PATHだけ確認したい場合はecho $PATHで十分です。

とりあえず現状を確認します。

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

パスを追加する場合は、

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/linuxbrew/.linuxbrew/bin

とします。
export PATH=/home/linuxbrew/.linuxbrew/bin
としてしまうと、元々通っていたPATHが通らなくなってしますので要注意。
実行したら改めてPATHを確認してみましょう。

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/linuxbrew/.linuxbrew/bin

PATHが通ったのことが確認できました。
$ brew -v を実行するとバージョンも表示されると思います。

$ brew -v
Homebrew 4.2.6

これでDebianへのHomebrewのインストールは完了です。

追記

上記のPATH設定は一時的なPATHの追加方法でした。
永続的なPATH追加も記載しておきます。

PATHの記載場所

Debianの場合、PATHを追記する場合は ~/.profile に追記します。

PATHの追記
$ vi ~/.profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
~~~(省略)~~~
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

 export PATH="$PATH:/home/linuxbrew/.linuxbrew/bin  ←追記

上記の通り、~/.profileの最後の行に追記してあげればOKです。

保存したら反映させてあげましょう

$ source ~/.profile

$ echo $PATH や $ brew -v
で表示を確認しましょう。パスやバージョンが表示されれば完了です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?