3
1

More than 3 years have passed since last update.

Homebrewパッケージを整理する

Last updated at Posted at 2020-03-10

このころmacの容量が足りなくなってきたので、とりあえず使っていないパッケージを削除していきます。

使用されていないパッケージを消す

1. homebrewでインストールされている物の総容量を測る

homebrewはデフォルトでは/usr/local/Cellar(caskは/usr/local/Caskroom)にインストールするので、ここの容量を測ります

# `-d1` で一つの階層のみ指定
# `-h` で読みやすい(Human readable)形式での表示を指定
$ du -d1 -h /usr/local | egrep 'Caskroom|Cellar'
770M    /usr/local/Caskroom
 11G    /usr/local/Cellar

Cellarがそれなりに容量食っていますね...
何か減らせるか試みてみます

2. 重いファイルを探す

Cellar以下で、どのパッケージが重いのかを確かめます

# sort -n で数字の順にソート
$ du  -d1 /usr/local/Cellar | sort -n
...
64      /usr/local/Cellar/pstree
64      /usr/local/Cellar/shellshare
72      /usr/local/Cellar/goto
88      /usr/local/Cellar/git-cal
96      /usr/local/Cellar/tldr
...
14096   /usr/local/Cellar/openldap
14288   /usr/local/Cellar/libarchive
14496   /usr/local/Cellar/termshare
14672   /usr/local/Cellar/msgpack
14688   /usr/local/Cellar/swig
15320   /usr/local/Cellar/eigen
15344   /usr/local/Cellar/shyaml
15456   /usr/local/Cellar/shellcheck
...
717552  /usr/local/Cellar/qt
860672  /usr/local/Cellar/mono
978408  /usr/local/Cellar/go
1131640 /usr/local/Cellar/boost
1196752 /usr/local/Cellar/gcc
1764448 /usr/local/Cellar/rust
3158152 /usr/local/Cellar/ghc
6920016 /usr/local/Cellar/llvm
24014992        /usr/local/Cellar

llvm/ghc/rust/gcc/boost/goあたりが特に大きいようですね。
基本的に使うものばかりなのですが、自分はrust/goを書かないのでこれはできればアンインストールしたいところです。

3. パッケージが他のhomebrewパッケージに依存されているか確認する

注意

rust/goは自分で意識的にいれていないので、なんらかのパッケージが依存しているはずです。
brew uses <package>で、<package>を依存パッケージに指定しているパッケージのリストを表示できます。
(デフォルトではrequiredもしくはrecommendedとして指定しているものを表示します)

brew-uses
<X_X>:~$ brew uses -h
Usage: brew uses [options] formula

Show formulae that specify formula as a dependency. When given multiple
formula arguments, show the intersection of formulae that use formula. By
default, uses shows all formulae that specify formula as a required or
recommended dependency for their stable builds.

        --recursive                  Resolve more than one level of
                                     dependencies.
        --installed                  Only list formulae that are currently
                                     installed.
        --include-build              Include all formulae that specify formula
                                     as :build type dependency.
        --include-test               Include all formulae that specify formula
                                     as :test type dependency.
        --include-optional           Include all formulae that specify formula
                                     as :optional type dependency.
        --skip-recommended           Skip all formulae that specify formula as
                                     :recommended type dependency.
        --devel                      Show usage of formula by development
                                     builds.
        --HEAD                       Show usage of formula by HEAD builds.
    -d, --debug                      Display any debugging information.
    -h, --help                       Show this message.

今回は「インストール済みのパッケージに使われているか」が知りたいので--installedを指定します。

$ brew uses --installed go
# 出力なし
$ brew uses --installed rust
cj-bc/sonic-pi-tool/sonic-pi-tool

どうやら、goは依存されているパッケージはなし、rustsonic-piに使用されているようですね
sonic-piはrubyライブコーディング環境です。お試しで入れたのですが、ruby分からず使っていないので削除することにします。

$ brew uninstall sonic-pi-tool rust go
Uninstalling /usr/local/Cellar/sonic-pi-tool/HEAD... (4 files, 1.1MB)
Uninstalling /usr/local/Cellar/rust/1.36.0... (26,366 files, 784.7MB)
Uninstalling /usr/local/Cellar/go/1.12.7... (9,816 files, 452.7MB)
$ du -d1 -h /usr/local | grep Cellar
 10G    /usr/local/Cellar

約1GB減った!わ〜い!!
この調子で地道に減らしていき...結局2GBくらい減りました!!!

2GBなんてすぐ溶けるじゃねぇか!!!

$ du -h -d1 /usr/local/ | egrep 'Cellar'
9.0G    /usr/local//Cellar

依存パッケージの確認について

homebrewで管理されている(かつきちんと依存指定されている)ものについてはbrew usesで確認できますが、そうでない場合もありそうです
実際の例として、dlibboostに依存していると思うのですが表示されませんでした。
別の方法で入ってるのかもしれないし、homebrew経由で入れるときはboostいらないのかもしれません。
わからん!!
どなたか知っている方がいたらコメントなりで書いていただけると嬉しいです。
また、このほかにも「自分で書いたプログラムで使ってたわ」とかあると思うので、気をつけるようにしてください。

おまけ

homebrewのコマンド一覧はbrew commandsで表示できます。

$ brew commands
3
1
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
3
1