Linux または WSL に Homebrew をインストールする方法 - Linux 用 Windows サブシステム

Homebrew は macOS にさまざまなソフトウェアをインストールするためのパッケージ管理ソフトウェアですが、このオープンソースを使用することもできますWindows WSL および Debian、Ubuntu、Linux Mint、Fedora、CentOS、RedHat などの Linux オペレーティング システム上での Brew…Homebrew は、macOS で最高のパッケージ管理ツールです。 Linux で使用される場合、Homebrew は Linuxbrew として知られます。

Linux または WSL への HomeBrew のインストール


パッケージを別のディレクトリにインストールし、そのファイルを/usr/local。簡単に言うと、Linux に apt と yum を使用してさまざまなパッケージをインストールするのと同じです。同様に、Homebrew はソフトウェア パッケージを、パッケージに必要な依存関係とともに統合された方法でインストールおよび管理します。保管場所などを気にする必要はありません。

注記: Linux 用の Windows サブシステムで使用するには、まずこれを使用してセットアップします。無料の WSL チュートリアル。

ステップ 1: ターミナルを開き、システム更新コマンドを実行します。


デスクトップまたはサーバー上の Linux ディストリビューションに応じて、システム アップデート コマンドを実行します。ここでは、最も一般的なコマンドについて説明します。

Ubuntu および Debian ベースのシステム:

sudo apt update

RedHat または CentOS ベース:

sudo yum update

ステップ 2: Brew の依存関係をインストールする


Brew をセットアップするには、システム上に次のものが必要です。GCC、Glibc、および 64 ビット x86_64 CPU。現在では一般的な 64 ビット CPU をすでに使用していると思いますが、残りの部分については、システムに応じて以下のコマンドを使用してください。

Debian、Linux Mint、Ubuntu、またはその他の同様の OS の場合

sudo apt-get install build-essential curl file git

RedHat、Fedora、CentOS、またはその他の同種の Linux OS の場合

sudo yum groupinstall 'Development Tools'
sudo yum install curl file git
sudo yum install libxcrypt-compat

ステップ 3: HomeBrew をダウンロードしてインストールするコマンド


次に、以下のコマンドをコピーして貼り付けるだけで、Linux または WSL での brew のセットアップに必要なマスター スクリプト ファイルがダウンロードされます。

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
HomeBrew をインストールする

ステップ 4: Homebrew をシステム PATH に追加する


現在いるディレクトリに関係なく、ターミナルのどこからでもこのパッケージ マネージャーの brew コマンドを実行するには、それを bin に追加してシステムに通知する必要があります。 Linux システムで次のコマンドを 1 つずつ実行します。

test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
Homebrew をシステムの PATH に追加します

Linux または Linux 用 Windows サブシステムで Brew コマンドを使用する例


さて、パッケージ マネージャーがシステム上にあるので、いくつかのパッケージをインストールしてみましょう。たとえば、git または Python

brew を使用して git をインストールする、コマンドは次のようになります。

brew install git

Python の場合:

brew install python

上記の git コマンドの出力は次のとおりです。

h2s@DESKTOP-9OOKS69:~$ brew install git
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
No changes to formulae.

==> Installing dependencies for git: ncurses, gettext, bzip2, zlib, pcre2, [email protected], curl, libbsd and expat
==> Installing git dependency: ncurses
==> Downloading https://linuxbrew.bintray.com/bottles/ncurses-6.1_1.x86_64_linux.bottle.tar.gz
Already downloaded: /home/h2s/.cache/Homebrew/downloads/d4ea71074c7ccba18fb75489ae89e777e360d9621d19447f0336e1a02908c632--ncurses-6.1_1.x86_64_linux.bottle.tar.gz
==> Pouring ncurses-6.1_1.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/ncurses/6.1_1: 3,860 files, 9.0MB
==> Installing git dependency: gettext
==> Downloading https://linuxbrew.bintray.com/bottles/gettext-0.20.1_1.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/72/724879481408d819c1b49787e14f95657fb1c6607b51c0a943773b773298e349?__gd
######################################################################## 100.0%
==> Pouring gettext-0.20.1_1.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/gettext/0.20.1_1: 1,892 files, 20.2MB
==> Installing git dependency: bzip2
==> Downloading https://linuxbrew.bintray.com/bottles/bzip2-1.0.8.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/e5/e5fce257b9fee119d28d0e7f7dac9332bd26b248fe35d983ba85104243e4bc2e?__gd
######################################################################## 100.0%
==> Pouring bzip2-1.0.8.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/bzip2/1.0.8: 30 files, 521.3KB
==> Installing git dependency: zlib
==> Downloading https://linuxbrew.bintray.com/bottles/zlib-1.2.11.x86_64_linux.bottle.tar.gz
######################################################################## 100.0%
==> Pouring zlib-1.2.11.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/zlib/1.2.11: 12 files, 396KB
==> Installing git dependency: pcre2
==> Downloading https://linuxbrew.bintray.com/bottles/pcre2-10.34.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/49/497ae0c6e7f7e8bb9dd7555cf8a6aec0dd6a84b052751741fe8fb55ec70799db?__gd
######################################################################## 100.0%
==> Pouring pcre2-10.34.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/pcre2/10.34: 235 files, 6.6MB
==> Installing git dependency: [email protected]
==> Downloading https://linuxbrew.bintray.com/bottles/[email protected]_1.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/01/010a4e5257eb685ac700f495208bed1e05155663f8083ab6ab2e4a91ef69c1cd?__gd
######################################################################## 100.0%
==> Pouring [email protected]_1.x86_64_linux.bottle.tar.gz
==> Downloading https://curl.haxx.se/ca/cacert-2019-10-16.pem
######################################################################## 100.0%
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/home/linuxbrew/.linuxbrew/etc/[email protected]/certs

and run
/home/linuxbrew/.linuxbrew/opt/[email protected]/bin/c_rehash

[email protected] is keg-only, which means it was not symlinked into /home/linuxbrew/.linuxbrew,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH run:
echo 'export PATH="/home/linuxbrew/.linuxbrew/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/[email protected]/lib"
export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/[email protected]/include"

For pkg-config to find [email protected] you may need to set:
export PKG_CONFIG_PATH="/home/linuxbrew/.linuxbrew/opt/[email protected]/lib/pkgconfig"

==> Summary
🍺 /home/linuxbrew/.linuxbrew/Cellar/[email protected]/1.1.1d_1: 7,985 files, 20.8MB
==> Installing git dependency: curl
==> Downloading https://linuxbrew.bintray.com/bottles/curl-7.68.0.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/90/90f8495c253eccee411204ac859a90a99c145ffd13198b277e7304a2122f6ede?__gd
######################################################################## 100.0%
==> Pouring curl-7.68.0.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/curl/7.68.0: 460 files, 3.7MB
==> Installing git dependency: libbsd
==> Downloading https://linuxbrew.bintray.com/bottles/libbsd-0.10.0.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/68/68ac94cf2b7530dcb4b678402d37d7fce907cd628821d5b7549b644146947951?__gd
######################################################################## 100.0%
==> Pouring libbsd-0.10.0.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/libbsd/0.10.0: 261 files, 897.2KB
==> Installing git dependency: expat
==> Downloading https://linuxbrew.bintray.com/bottles/expat-2.2.9.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/5d/5d0281695b1febb80cb2dc3c64d61e586ebe1870202d4f763650ab127d2b9f01?__gd
######################################################################## 100.0%
==> Pouring expat-2.2.9.x86_64_linux.bottle.tar.gz
🍺 /home/linuxbrew/.linuxbrew/Cellar/expat/2.2.9: 18 files, 711.8KB
==> Installing git
==> Downloading https://linuxbrew.bintray.com/bottles/git-2.25.0_1.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/bf/bf6ec84bf7db2334df764e74dd146e5a4b3ac8b0d7271723989f1ddc3d2b7b2b?__gd
######################################################################## 100.0%
==> Pouring git-2.25.0_1.x86_64_linux.bottle.tar.gz
==> Caveats
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.
<--more--->

git を使用するには、次のように入力するだけですGitクローンを作成または更新するファイルと一緒に。

このパッケージ マネージャーを介して Ubuntu Linux WSL に GIT をインストールする

ソフトウェア情報を表示する


homebrew を使用してインストールされているパッケージの情報を確認するには、これを使用するだけです。

brew info <package name>

上の例では git と python をインストールしたため、そのバージョンやその他の情報を知るために次のコマンドを使用します。

brew info git

出力は次のようになります。

h2s@DESKTOP-9OOKS69:~$ brew info git
git: stable 2.25.0 (bottled), HEAD
Distributed revision control system
https://git-scm.com
/home/linuxbrew/.linuxbrew/Cellar/git/2.25.0_1 (1,446 files, 50MB) *
Poured from bottle on 2020-02-05 at 15:57:39
From: https://github.com/Homebrew/linuxbrew-core/blob/master/Formula/git.rb
==> Dependencies
Required: gettext ✔, pcre2 ✔, [email protected] ✔, curl ✔, expat ✔, zlib ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.

Bash completion has been installed to:
/home/linuxbrew/.linuxbrew/etc/bash_completion.d

Emacs Lisp files have been installed to:
/home/linuxbrew/.linuxbrew/share/emacs/site-lisp/git
==> Analytics
install: 4,712 (30 days), 12,008 (90 days), 41,210 (365 days)
install-on-request: 4,675 (30 days), 11,930 (90 days), 40,989 (365 days)
build-error: 0 (30 days)
ソフトウェア情報の表示 brew 経由でインストール

インストールされているソフトウェアを表示する


いつでも、このパッケージ マネージャーを使用してシステムにインストールされているソフトウェアまたはパッケージを知りたい場合は、次のコマンドを使用します。

brew list
インストールされているパッケージを知る

ソフトウェアのアンインストール


インストールされているパッケージを削除するには、次のパッケージを使用します。

brew uninstall <package_name>

たとえば、上記では git を設定しているため、同じものを削除するには、コマンドは次のようになります。

brew uninstall git

Git のみに限定されるわけではなく、Nginx やその他多くのものをインストールできます。ボトルとして知られる Homebrew のすべてのバイナリ パッケージは、GitHub アクションそして主催者はビントレイ

システムから Homebrew をアンインストールする方法


何らかの理由でシステムから自作を削除したい場合は、以下の構文を実行します。

まず、Ubuntu または Debian システムに Ruby をインストールします。

sudo apt install ruby

RedHat または CentOS の場合

sudo yum install ruby

アンインストールスクリプトを実行する

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Brew のコマンドの使用方法について詳しくは、公式ドキュメントを参照してください。自作ドキュメント

Homebrew には、macOS への GUI アプリケーションのインストールを高速化するための「Homebrew Cask」として知られる拡張機能もありますが、サポートできるのは MAC のみであるため、ここでは知識のみを提供します。興味のある方はアクセスしてください。」自家製カスク」について学びます。有効にするには、次のように入力するだけですbrew cask

その他の記事: