LoginSignup
0
2

More than 1 year has passed since last update.

LinuxにHomebrewを入れてみる

Last updated at Posted at 2021-10-09

とても便利なHomebrew

macOSにはLinuxでいうところのyumやaptの様なOS付属のパッケージマネージャがありませんが、OSSのプロジェクトが幾つか存在します。その中でも最も利用者が多いのではないかと思われるHomebrewは、QiitaのmacOSの記事でも、セットアップしたらまずはHomebrewをインストールする、と紹介されているくらいポピュラーなツールとなっています。

以前はMacPortsというパッケージマネージャもよく聞きましたが、こちらはあまり使ったことがないので今回は触れません。

LinuxにもHomebrewあるの…?

前述の通り、Linuxには元々パッケージマネージャが存在するので、他のパッケージマネージャが欲しいな~と感じることは基本的にありません。必要なソフトウェアに応じて、そのパッケージが提供されているリポジトリを追加したりすることがあることくらいでしょうか。ただ、このリポジトリ追加もなかなかくせ者で、同じソフトウェアが複数のリポジトリで公開されている場合は優先度的に衝突したり不整合が発生することもありますし、リポジトリのポリシーにより提供されているバージョンの最新版への追従度等が異なったりすることあります。

こんな時デスクトップ(作業端末)用途だと、サーバ向け程の厳密性や安定性は要らないから、適度に新しくて後腐れなくもっと簡単に扱えるものがあれば便利だよな~、LinuxでもHomebrew使いたいね~と思っていたら、よく見たらLinuxにも対応していると書かれています。早速インストールしてみます。

導入環境

今回はWinodows 10 Pro 21H1上のWSL2で動作しているUbuntu 20.04に対してHomebrewを導入してみます。

インストール

Homebrewといえば、シェルのワンライナーでサクッとインストールできるのが特徴の一つです。Linux版ではどうでしょうか。

Linux版のHomebrewの公式サイトにアクセスすると、インストール方法が確認できます。

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

Paste that in a macOS Terminal or Linux shell prompt.

Homebrewのインストール方法はmacOSと全く同じでした。

ワンライナーを実行すると、パッケージマネージャ本体をインストールするためsudoで管理者権限を要求されますので、パスワードを入力します。すると、必要なディレクトリの作成やgitによる構成ファイルのダウンロードが自動的に行われてインストールが完了します。ほんとに簡単ですね!

インストールが完了すると、「Next Steps」として以下が提示されます。

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/kansaizine/.profile
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- Run `brew help` to get started
- Further documentation:
    https://docs.brew.sh
- Install the Homebrew dependencies if you have sudo access:
    sudo apt-get install build-essential
    See https://docs.brew.sh/linux for more information
- We recommend that you install GCC:
    brew install gcc

案内通り、Homebrewをパスに追加するために以下を実行します。

$ echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/kansaizine/.profile
$ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

1行目は次回以降も自動的に有効化される様に.profileファイルへの設定、2行目は現在実行しているシェル上で即時有効化するためのものですね。

パッケージのインストール

パッケージマネージャ本体の導入が完了したので、次はパッケージをインストールしてみます。

先ほどのNext StepsにてGCCのインストールが推奨されていましたので、こちらをインストールしておきましょう。Homebrewで初めてインストールするパッケージですね。

$ brew install gcc
==> Downloading https://ghcr.io/v2/linuxbrew/core/gmp/manifests/6.2.1_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/gmp/blobs/sha256:786ae29f0c0b06ea86e42bd9c6ac2c49bd5757da037dead7053e8bd612c4cf8c
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:786ae29f0c0b06ea86e42bd9c6ac2c49bd5757da037dead7053e8bd612c4cf8
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/isl/manifests/0.24
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/isl/blobs/sha256:7b58d25de0b7ed797118f32febe116ee2d7458767e6339d6a4ce51ff4ab11191
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:7b58d25de0b7ed797118f32febe116ee2d7458767e6339d6a4ce51ff4ab1119
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/mpfr/manifests/4.1.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/mpfr/blobs/sha256:5fa04c762dd682c46b3c15d2c28e89a36353717c533e7aaa12298b5202aeeba8
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:5fa04c762dd682c46b3c15d2c28e89a36353717c533e7aaa12298b5202aeeba
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/libmpc/manifests/1.2.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/libmpc/blobs/sha256:c12f0406fb375c08d4c9f699ec2d28099088bb999fe9cceefe9145c001f24f89
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:c12f0406fb375c08d4c9f699ec2d28099088bb999fe9cceefe9145c001f24f8
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/zlib/manifests/1.2.11
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/zlib/blobs/sha256:6f604280b9e056da163b81cef3076b2e39bbd2b8d3cc8c36d27c19c472c760a4
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:6f604280b9e056da163b81cef3076b2e39bbd2b8d3cc8c36d27c19c472c760a
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/zstd/manifests/1.5.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/zstd/blobs/sha256:35f3d0c3e35229b4b9d32a2315f061651ee1cf88e2d5216ec259f2aece4dafb3
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:35f3d0c3e35229b4b9d32a2315f061651ee1cf88e2d5216ec259f2aece4dafb
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/binutils/manifests/2.37
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/binutils/blobs/sha256:719fb08218906d67d42eaca5ade0b8deaec6dbb03184a9e968214187d7f04bfa
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:719fb08218906d67d42eaca5ade0b8deaec6dbb03184a9e968214187d7f04bf
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/gcc/manifests/11.2.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/gcc/blobs/sha256:b77106d6f2a36dd0c9a0a4396cc77a71e81880bb9984ca68a0f986253f537053
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:b77106d6f2a36dd0c9a0a4396cc77a71e81880bb9984ca68a0f986253f53705
######################################################################## 100.0%
==> Installing dependencies for gcc: gmp, isl, mpfr, libmpc, zlib, zstd and binutils
==> Installing gcc dependency: gmp
==> Pouring gmp--6.2.1_1.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/gmp/6.2.1_1: 23 files, 3.9MB
==> Installing gcc dependency: isl
==> Pouring isl--0.24.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/isl/0.24: 74 files, 8.9MB
==> Installing gcc dependency: mpfr
==> Pouring mpfr--4.1.0.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/mpfr/4.1.0: 30 files, 7.9MB
==> Installing gcc dependency: libmpc
==> Pouring libmpc--1.2.1.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/libmpc/1.2.1: 14 files, 549.9KB
==> Installing gcc dependency: zlib
==> Pouring zlib--1.2.11.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/zlib/1.2.11: 12 files, 424.2KB
==> Installing gcc dependency: zstd
==> Pouring zstd--1.5.0.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/zstd/1.5.0: 31 files, 3.2MB
==> Installing gcc dependency: binutils
==> Pouring binutils--2.37.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/binutils/2.37: 4,594 files, 261.3MB
==> Installing gcc
==> Pouring gcc--11.2.0.x86_64_linux.bottle.tar.gz
==> Creating the GCC specs file: /home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-pc-linux-gnu/11.2.0/specs
🍺  /home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0: 2,194 files, 348.2MB

Depencency(依存性)を解決しながらパッケージのインストールが完了しました。Homebrewでおなじみのビールのアイコンも表示されていますね!

Homebrewでインストールされたgccは11.2.0という非常に新しいバージョンでした。これほど新しいバージョンがOSのリポジトリで提供されるのは数年かかるでしょうから、新しいもの好きのエンジニアにとっては嬉しいですね。

gccはOS側でもデフォルトで導入されている可能性が高いので、「gcc-11」という名前でインストールされている様です。既にパスが通っているのでシェル上で実行することで使用することが出来ました。

$ gcc-11 -v
Reading specs from /home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-pc-linux-gnu/11.2.0/specs
COLLECT_GCC=gcc-11
COLLECT_LTO_WRAPPER=/home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0 --libdir=/home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0/lib/gcc/11 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/home/linuxbrew/.linuxbrew/opt/gmp --with-mpfr=/home/linuxbrew/.linuxbrew/opt/mpfr --with-mpc=/home/linuxbrew/.linuxbrew/opt/libmpc --with-isl=/home/linuxbrew/.linuxbrew/opt/isl --with-zstd=/home/linuxbrew/.linuxbrew/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0' --with-bugurl=https://github.com/Homebrew/linuxbrew-core/issues --enable-libphobos --with-boot-ldflags='-static-libstdc++ -static-libgcc ' --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Homebrew GCC 11.2.0)

まとめ

Linuxにも公式版のHomebrewが存在しました。インストールも簡単で、導入されるパッケージも非常に新しいということで、特に開発環境や作業端末では活躍してくれるのではないかと思います。

WSLにも導入できますので、Windowsな皆さんも使ってみてください。

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