macOS ユーザの皆さん、こんにちは。はむさんです。
さて、みなさんは、パッケージマネージャはお使いでしょうか?
ウェブ開発においては、特に Linux の世界では当たり前のように使われているこのパッケージマネージャですが、必要な機能を正確にインストールするにはとっても便利な機能になりますね。
しかしながら、標準の macOS にはこのパッケージマネージャという機能は残念ながら提供されていません。
そこで今回紹介するのが Homebrew
です。
この Homebrew は、brew と短く呼ぶこともありますので、以降は短い方で呼んでいきます。この brew の公式サイトは、 homebrew
で検索すると見つかるかと思います。
URL は、 https://brew.sh/index_ja です。
今回、なぜ、brew を紹介するのかと言うと、 この brew は、macOS のために開発されたパッケージマネージャーなんです。 この brew を使って、nodenv や node、あるいは rbenv とか ruby とか、あるいは git や bash 等、ウェブ開発者にとって欠かせないパッケージを簡単にインストールしたり管理することができるからなんです。
Linux、例えば、CentOS であれば yum コマンド、あるいは、Ubuntu であれば apt-get コマンドなどでパッケージのインストールをしたことがある人もいるかもしれませんが、macOS において、それらに該当するものがこの brew
になります。
macOS でも yum や apt-get と同じように、この brew を一度入れてしまえば、煩わしい パッケージのインストールをコマンドライン一発で進めていけるというのはプログラマーにとって非常にありがたいですよね。
mac を持っている大抵のプログラマーは、mac を買ってきて、電源を入れたらすぐにこの brew をインストールする!っていっても過言じゃないくらいの鉄板のツールとなっています。インストールも簡単なので、まだ使ったことがないと言う方は是非この機会に入れてみてください。
では、brew コマンドをインストールをしていきますが、まず、インストール前に、コマンドがないこと確かめておきますね。
画面右上の Spotlight 検索のアイコンをクリックして、Terminal.app と入力して、ターミナルを開きます。
$ type brew-zsh: type: brew: not found
brew についても type コマンドでコマンドがあるかどうかみてみると、この通り、not found
って表示されますよね。
デフォルトの状態だとこのようにコマンドがありません!と表示されます。
Homebrew のホームページはこちらです。
では、こちらの Homebrew のリンクをクリックして、Homebrew のトップページに移って、
「インストール
」のところにある、こちらの コマンドをコピーしてターミナルに貼り付けましょう!
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"==> Checking for `sudo` access (which may request your password).Password:==> This script will install:/usr/local/bin/brew/usr/local/share/doc/homebrew/usr/local/share/man/man1/brew.1/usr/local/share/zsh/site-functions/_brew/usr/local/etc/bash_completion.d/brew/usr/local/Homebrew==> The Xcode Command Line Tools will be installed.Press RETURN to continue or any other key to abort==> /usr/bin/sudo /usr/sbin/chown -R ham:admin /usr/local/Homebrew==> Searching online for the Command Line Tools==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress==> Installing Command Line Tools for Xcode-13.1==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-13.1Software Update Tool:::
すると、あとはインストーラが走ります。途中で、「インストールを続けても良いなら RETURN を押してね!」って言っています。 ここで RETURN キーを叩きます!
==> /usr/bin/sudo /usr/sbin/chown -R ham:admin /usr/local/Homebrew==> Downloading and installing Homebrew...remote: Enumerating objects: 69, done.remote: Counting objects: 100% (66/66), done.remote: Compressing objects: 100% (25/25), done.remote: Total 69 (delta 49), reused 45 (delta 40), pack-reused 3Unpacking objects: 100% (69/69), 25.69 KiB | 392.00 KiB/s, done.From https://github.com/Homebrew/brew+ 19e059235...d42aff248 buildpulse-retry -> origin/buildpulse-retry (forced update)+ 1d34c7a91...a9059239f dependabot/bundler/Library/Homebrew/rubocop-rails-2.11.1 -> origin/dependabot/bundler/Library/Homebrew/rubocop-rails-2.11.1 (forced update)aa14e48f4..51cfd7362 master -> origin/masterHEAD is now at 51cfd7362 Merge pull request #11601 from Homebrew/dependabot/bundler/Library/Homebrew/activesupport-6.1.4Updated 3 taps (homebrew/cask-versions, homebrew/core and homebrew/cask).==> 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/AnalyticsNo analytics data has been sent yet (or will be during this `install` run).==> Homebrew is run entirely by unpaid volunteers. Please consider donating:https://github.com/Homebrew/brew#donations==> Next steps:- Run `brew help` to get started- Further documentation:https://docs.brew.sh
続きは上のような感じで処理が続きます。
Installation successful
という案内が表示されます。
インストールが成功したようです!
ここまで来たら正常に brew がインストールされたことになります。 brew help と入力してエンターキーを押してみましょう。
$ brew helpExample usage:brew search TEXT|/REGEX/brew info [FORMULA|CASK...]brew install FORMULA|CASK...brew updatebrew upgrade [FORMULA|CASK...]brew uninstall FORMULA|CASK...brew list [FORMULA|CASK...]Troubleshooting:brew configbrew doctorbrew install --verbose --debug FORMULA|CASKContributing:brew create URL [--no-fetch]brew edit [FORMULA|CASK...]Further help:brew commandsbrew help [COMMAND]man brewhttps://docs.brew.sh
brew help
を実行すると、ご覧のように brew コマンドに関するヘルプが表示されます。
あとは適宜必要なパッケージをインストールするだけです。
では、折角なので、 brew
を使ってパッケージのインストールを行ってみましょう。brew
でインストールできる有名なパッケージに wget というファイルダウンローダがありますのでこれを入れてみましょう。まず、デフォルトだとwget
コマンドは macOS にはインストールされていませんので type コマンドで確認しておきます。
$ type wget-bash: type: wget: not found
はい、この通り wget
コマンドは見つかりませんでした。では、 brew
コマンドで wget
コマンドを検索してみます。
$ brew search wget==> Formulaewget wgetpaste
検索するには、brew のサブコマンドである search、そして引数に wget を渡します。 すると、検索結果に wget が表示されましたね。
wget
パッケージの詳細を brew info
コマンドで調べてみましょう。
$ brew info wgetwget: stable 1.21.2 (bottled), HEADInternet file retrieverhttps://www.gnu.org/software/wget//usr/local/Cellar/wget/1.21.2 (89 files, 4.2MB) *Poured from bottle on 2021-11-09 at 20:47:07From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/wget.rbLicense: GPL-3.0-or-later==> DependenciesBuild: pkg-config ✔Required: libidn2 ✔, openssl@1.1 ✔==> Options--HEADInstall HEAD version==> Analyticsinstall: 178,233 (30 days), 654,470 (90 days), 1,930,917 (365 days)install-on-request: 177,723 (30 days), 651,709 (90 days), 1,921,977 (365 days)build-error: 14 (30 days)
brew info wget
を実行すると、色々と情報が表示されました。
ここで分かるのは、公式のページが https://www.gnu.org/software/wget/ であることです。
公式ページをみてみると、wget の概要について書かれています。
では、wget を brew でインストールしてみましょう。実行するコマンドは、brew install wget
です。
$ brew install wget==> Installing dependencies for wget: gettext, libunistring, libidn2 and openssl==> Installing wget dependency: gettext==> Downloading https://homebrew.bintray.com/bottles/gettext-0.######################################################################## 100.0%==> Pouring gettext-0.19.8.1.high_sierra.bottle.tar.gz==> Caveatsgettext is keg-only, which means it was not symlinked into /usr/local,because macOS provides the BSD gettext library & some software gets confused if both are in the library path.If you need to have gettext first in your PATH run:echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profileFor compilers to find gettext you may need to set:export LDFLAGS="-L/usr/local/opt/gettext/lib"export CPPFLAGS="-I/usr/local/opt/gettext/include"==> Summary🍺 /usr/local/Cellar/gettext/0.19.8.1: 1,935 files, 16.9MB==> Installing wget dependency: libunistring==> Downloading https://homebrew.bintray.com/bottles/libunistri######################################################################## 100.0%==> Pouring libunistring-0.9.10.high_sierra.bottle.tar.gz🍺 /usr/local/Cellar/libunistring/0.9.10: 54 files, 4.4MB==> Installing wget dependency: libidn2==> Downloading https://homebrew.bintray.com/bottles/libidn2-2.######################################################################## 100.0%==> Pouring libidn2-2.1.1a.high_sierra.bottle.tar.gz🍺 /usr/local/Cellar/libidn2/2.1.1a: 69 files, 691.6KB==> Installing wget dependency: openssl==> Downloading https://homebrew.bintray.com/bottles/openssl-1.######################################################################## 100.0%==> Pouring openssl-1.0.2r.high_sierra.bottle.tar.gz==> CaveatsA CA file has been bootstrapped using certificates from the SystemRootskeychain. To add additional certificates (e.g. the certificates added inthe System keychain), place .pem files in/usr/local/etc/openssl/certsand run/usr/local/opt/openssl/bin/c_rehashopenssl is keg-only, which means it was not symlinked into /usr/local,because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.If you need to have openssl first in your PATH run:echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profileFor compilers to find openssl you may need to set:export LDFLAGS="-L/usr/local/opt/openssl/lib"export CPPFLAGS="-I/usr/local/opt/openssl/include"==> Summary🍺 /usr/local/Cellar/openssl/1.0.2r: 1,795 files, 12.1MB==> Installing wget==> Downloading https://homebrew.bintray.com/bottles/wget-1.20.######################################################################## 100.0%==> Pouring wget-1.20.1_4.high_sierra.bottle.tar.gz🍺 /usr/local/Cellar/wget/1.20.1_4: 49 files, 3.9MB==> `brew cleanup` has not been run in 30 days, running now...Pruned 0 symbolic links and 2 directories from /usr/local==> Caveats==> gettextgettext is keg-only, which means it was not symlinked into /usr/local,because macOS provides the BSD gettext library & some software gets confused if both are in the library path.If you need to have gettext first in your PATH run:echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profileFor compilers to find gettext you may need to set:export LDFLAGS="-L/usr/local/opt/gettext/lib"export CPPFLAGS="-I/usr/local/opt/gettext/include"==> opensslA CA file has been bootstrapped using certificates from the SystemRootskeychain. To add additional certificates (e.g. the certificates added inthe System keychain), place .pem files in/usr/local/etc/openssl/certsand run/usr/local/opt/openssl/bin/c_rehashopenssl is keg-only, which means it was not symlinked into /usr/local,because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.If you need to have openssl first in your PATH run:echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profileFor compilers to find openssl you may need to set:export LDFLAGS="-L/usr/local/opt/openssl/lib"export CPPFLAGS="-I/usr/local/opt/openssl/include":::==> gettextgettext is keg-only, which means it was not symlinked into /usr/local,because macOS provides the BSD gettext library & some software gets confused if both are in the library path.If you need to have gettext first in your PATH run:echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profileFor compilers to find gettext you may need to set:export LDFLAGS="-L/usr/local/opt/gettext/lib"export CPPFLAGS="-I/usr/local/opt/gettext/include"
はい、以上で、 wget
のインストールができました。wget のバージョンを確認してみましょう。
$ wget --versionGNU Wget 1.21.2 built on darwin21.1.0.-cares +digest -gpgme +https +ipv6 +iri +large-file -metalink +nls+ntlm +opie -psl +ssl/opensslWgetrc:/usr/local/etc/wgetrc (system)Locale:/usr/local/Cellar/wget/1.21.2/share/localeCompile:clang -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/usr/local/etc/wgetrc"-DLOCALEDIR="/usr/local/Cellar/wget/1.21.2/share/locale" -I.-I../lib -I../lib -I/usr/local/opt/openssl@1.1/include -DNDEBUG -g-O2Link:clang -DNDEBUG -g -O2 -lidn2 -L/usr/local/opt/openssl@1.1/lib -lssl-lcrypto -ldl -lz ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a-liconv -lintl -Wl,-framework -Wl,CoreFoundation -lunistringCopyright (C) 2015 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later<http://www.gnu.org/licenses/gpl.html>.This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.Originally written by Hrvoje Niksic <hniksic@xemacs.org>.Please send bug reports and questions to <bug-wget@gnu.org>.
では、バージョンが確認できたら、 wget
の動作を確認しましょう。
$ mkdir ~/tmp$ cd
まずは、ホームディレクトリの直下に tmp
という名前のディレクトリを作ります。
$ cd tmp
そして、 tmp
で移動します。
$ wget https://example.com/--2021-11-09 21:00:41-- https://example.com/Resolving example.com (example.com)... 93.184.216.34, 2606:2800:220:1:248:1893:25c8:1946Connecting to example.com (example.com)|93.184.216.34|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 1256 (1.2K) [text/html]Saving to: ‘index.html’index.html 100%[========================>] 1.23K --.-KB/s in 0s2021-11-09 21:00:41 (92.1 MB/s) - ‘index.html’ saved [1256/1256]
はい、こんな感じで index.html
というファイルがダウンロードできました。
$ head index.html<!doctype html><html><head><title>Example Domain</title><meta charset="utf-8" /><meta http-equiv="Content-type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><style type="text/css">body {
head
コマンドで index.html
ファイルの先頭の方の内容を覗いてみると、確かに html ファイルのような内容であることが確認できました。
と言うわけで、今回は、macOS ユーザのための鉄板ツール Homebrew のインストール手順のご紹介でした。