0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Homebrewのよく使われるコマンドメモ(使用例付)

Posted at

Macを使って普段の開発仕事でよく使われるbrewコマンドをまとめてみました。

パッケージのインストール・管理

brew install [パッケージ名]

# Node.jsをインストール
brew install node

# 複数のパッケージを同時にインストール
brew install git python3 wget curl

# 特定のバージョンを指定してインストール
brew install node@18

brew uninstall [パッケージ名]

# パッケージをアンインストール
brew uninstall node

# 依存関係も含めて完全削除
brew uninstall --zap docker

brew upgrade

# 特定のパッケージのみアップデート
brew upgrade node

# 全パッケージをアップデート
brew upgrade

# アップデート前に確認
brew outdated

情報確認

brew list

# インストール済みパッケージ一覧
brew list

# Caskアプリ一覧
brew list --cask

brew search

# パッケージ名で検索
brew search python

# 正規表現で検索
brew search "/^git.*/"

# Caskアプリも含めて検索
brew search --cask chrome

brew info

# パッケージの詳細情報
brew info node
# 出力例:バージョン、依存関係、インストールパス、説明など

# 複数パッケージの情報を一度に確認
brew info git python3 node

システム管理の実用例

brew doctor

brew doctor
# 出力例:
# Warning: Some installed formulae are missing dependencies.
# You should `brew install` the missing dependencies:
#   brew install autoconf

brew cleanup

# 古いバージョンのファイルを削除(容量節約)
brew cleanup

# 削除予定のファイルサイズを事前確認
brew cleanup --dry-run

# 特定のパッケージのみクリーンアップ
brew cleanup node

サービス管理の実例

データベースサービス

# MySQLを起動
brew services start mysql

# PostgreSQLを起動してログイン時に自動起動設定
brew services start postgresql@14

# Redisを停止
brew services stop redis

# 全サービスの状態確認
brew services list

開発サーバー

# Nginxを起動
brew services start nginx

# 再起動(設定変更後など)
brew services restart nginx

Cask(GUIアプリ)の実用例

開発ツール

# Visual Studio Codeをインストール
brew install --cask visual-studio-code

# Docker Desktopをインストール
brew install --cask docker

# 複数のアプリを一括インストール
brew install --cask google-chrome firefox slack zoom

アンインストール

# アプリをアンインストール
brew uninstall --cask visual-studio-code

# 設定ファイルも含めて完全削除
brew uninstall --cask --zap docker

実際の開発環境セットアップ例

Web開発環境

# 基本ツールのインストール
brew install git node yarn

# データベース
brew install mysql postgresql redis

# その他のツール
brew install --cask visual-studio-code docker postman

# サービス起動
brew services start mysql
brew services start postgresql
brew services start redis

Python開発環境

# Python関連
brew install python3 pipenv pyenv

# バージョン管理
pyenv install 3.11.0
pyenv global 3.11.0

トラブルシューティングの実例

権限エラーの解決

# Homebrewの権限を修正
sudo chown -R $(whoami) /usr/local/var/homebrew

パッケージの依存関係問題

# 依存関係をチェック
brew deps --tree node

# 壊れた依存関係を修復
brew doctor
brew reinstall [問題のあるパッケージ]

定期メンテナンス

# 週1回程度の定期メンテナンス
brew update && brew upgrade && brew cleanup && brew doctor
0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?