32
11

More than 3 years have passed since last update.

【Homebrew】Homebrewで入れたものをコード化して管理する方法

Posted at

はじめに

Homebrewのコード化する方法を知ったので、備忘録として残します。
PC入れ替えや不意な故障で再度環境構築する際に非常に便利ですね:point_up:

※現在Homebrewを使用中の方が対象です:bulb:

環境

OS: macOS Catalina 10.15.3
Homebrew: 2.2.11

手順

1. バックアップ

現在すでにbrew installしたものをBrewfileに書き出します。

$ brew bundle dump

※特に新しく入れる必要がなければ以降は無視でOKです、

2. 入れたいものをBrewfileに記入

例えば、gitを入れたいなら以下のようになります。

Brewfile
# ...略
brew "git"
# ...略

3. インストール

Brewfileに記載されていて、未インストールのものを入れます。

$ brew bundle 

以上です!超簡単!

あとはBrewfileGitで管理などバックアップ取っておけばPCがクラッシュしてもすぐ復旧できます:blush:


オプション

Brewfile内のものをコマンドラインで確認

$ brew bundle list

Brewfile内にないものを一括アンインストール

$ brew bundle cleanup

Brewfile内でインストール/アップグレードすべきものがないかの確認

$ brew bundle check

参考:Brewfileの中身ってどんなん?

公式より

Brewfile
tap "homebrew/cask"
tap "user/tap-repo", "https://user@bitbucket.org/user/homebrew-tap-repo.git"
cask_args appdir: "/Applications"

brew "imagemagick"
brew "denji/nginx/nginx-full", args: ["with-rmtp-module"]
brew "mysql@5.6", restart_service: true, link: true, conflicts_with: ["mysql"]

cask "firefox", args: { appdir: "~/my-apps/Applications" }
cask "google-chrome"
cask "java" unless system "/usr/libexec/java_home --failfast"

mas "1Password", id: 443987910

whalebrew "whalebrew/wget"

:arrow_down:参考までに、僕がbrew bundle dumpした直後はこんな感じでした。

Brewfile
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-fonts"
tap "homebrew/core"
tap "homebrew/services"
brew "readline"
brew "awscli"
brew "fd"
brew "git"
brew "git-flow"
brew "python"
brew "graphviz"
brew "kubernetes-cli"
brew "libiconv"
brew "libxml2"
brew "libxslt"
brew "lua"
brew "mysql@5.7"
brew "nodebrew"
brew "peco"
brew "postgresql", restart_service: true
brew "ruby-build"
brew "rbenv"
brew "redis"
brew "telnet"
brew "tfenv"
brew "tig"
brew "tmux"
brew "tree"
brew "vim"
brew "wget"
brew "yarn"
brew "zplug"
brew "zsh"
brew "zsh-completions"

おわりに

最後まで読んで頂きありがとうございました:bow_tone1:

どなたかの参考になれば幸いです:relaxed:

参考にさせて頂いたサイト(いつもありがとうございます)

32
11
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
32
11