# Referensi Cepat Homebrew

*Manajemen package, cask, tap, service, cleanup*

> Source: Homebrew Documentation (brew.sh) · MIT

## Instalasi

### Instal Homebrew

```
/bin/bash -c "$(curl -fsSL \
  https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew --version       # verify installation
```

### Setelah Instal (Apple Silicon)

```
# add Homebrew to PATH (Apple Silicon default)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' \
  >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
```

### Path Instalasi

| Command | Description |
|---------|-------------|
| `/opt/homebrew` | Prefix Apple Silicon (ARM) |
| `/usr/local` | Prefix Intel Mac |
| `/home/linuxbrew/.linuxbrew` | Prefix Linux |

## Manajemen Package

### Instal & Hapus

```
brew install git           # install formula
brew install git@2.40      # install specific version
brew uninstall git         # remove formula
brew reinstall git         # reinstall formula
```

### Update & Upgrade

```
brew update                # update Homebrew itself
brew upgrade               # upgrade all packages
brew upgrade git           # upgrade specific package
brew pin git               # prevent auto-upgrade
brew unpin git             # allow upgrade again
```

### Daftar yang Terinstal

```
brew list                  # all installed formulae
brew list --cask           # all installed casks
brew leaves                # top-level (not dependencies)
brew deps git              # show dependencies of git
```

## Cari & Info

### Menemukan Package

```
brew search postgres       # search by name
brew search --cask chrome  # search casks only
brew info git              # package details
brew home git              # open homepage in browser
```

### Field Info

| Command | Description |
|---------|-------------|
| `Name / Version` | Nama package dan versi yang terinstal |
| `Dependencies` | Package yang dibutuhkan |
| `Conflicts` | Package yang tidak bisa berdampingan |
| `Caveats` | Catatan setelah instal (PATH, konfigurasi) |
| `Analytics` | Jumlah instal (30/90/365 hari terakhir) |

## Service

### Mengelola Service

```
brew services list             # all services + status
brew services start postgresql # start and auto-launch
brew services stop postgresql  # stop service
brew services restart nginx    # restart service
brew services run redis        # start without auto-launch
```

### Catatan Service

| Command | Description |
|---------|-------------|
| `start` | Jalankan sekarang + daftarkan untuk startup login |
| `run` | Jalankan sekarang saja (tanpa auto-start) |
| `stop` | Hentikan dan hapus dari startup |
| `restart` | Hentikan lalu jalankan kembali |
| `list` | Tampilkan semua service dan statusnya |
| `Logs` | Periksa `~/Library/Logs/Homebrew/` |

## Cask

### Manajemen Aplikasi GUI

```
brew install --cask firefox      # install GUI app
brew uninstall --cask firefox     # remove GUI app
brew upgrade --cask               # upgrade all casks
brew list --cask                  # list installed casks
```

### Cask Populer

| Command | Description |
|---------|-------------|
| `google-chrome` | Browser Chrome |
| `visual-studio-code` | Editor VS Code |
| `docker` | Docker Desktop |
| `iterm2` | Terminal iTerm2 |
| `slack` | Pesan Slack |
| `rectangle` | Manajemen jendela |
| `1password` | Manajer password |
| `raycast` | Launcher (pengganti Spotlight) |

## Tap

### Repository Pihak Ketiga

```
brew tap                         # list tapped repos
brew tap hashicorp/tap           # add a tap
brew untap hashicorp/tap         # remove a tap
brew install hashicorp/tap/terraform  # install from tap
```

### Tap Populer

| Command | Description |
|---------|-------------|
| `homebrew/cask` | Aplikasi GUI (sudah disertakan secara default) |
| `homebrew/cask-fonts` | Font: `brew install --cask font-fira-code` |
| `homebrew/bundle` | Dukungan Brewfile (Bundler untuk Homebrew) |
| `hashicorp/tap` | Terraform, Vault, Consul |

### Brewfile (Bundle)

```
brew bundle dump               # generate Brewfile
brew bundle install            # install from Brewfile
brew bundle cleanup            # remove unlisted packages
```

## Cleanup

### Membebaskan Ruang Disk

```
brew cleanup                 # remove old versions
brew cleanup -s              # also remove cache
brew cleanup --prune=all     # remove all cached downloads
brew autoremove              # remove unused dependencies
```

### Diagnostik

```
brew doctor                  # check for issues
brew config                  # show Homebrew config
brew missing                 # list missing dependencies
du -sh $(brew --cache)       # check cache size
```

## Pola Umum

### Alur Kerja Sehari-hari

| Command | Description |
|---------|-------------|
| `Update pagi` | `brew update && brew upgrade && brew cleanup` |
| `Setup Mac baru` | `brew bundle install` dari Brewfile |
| `Ekspor setup` | `brew bundle dump --file=~/Brewfile` |
| `Periksa kesehatan` | `brew doctor` |
| `Cari yang memakan ruang` | `brew list --formula \| xargs brew info` |
| `Hapus + dependensi` | `brew uninstall pkg && brew autoremove` |

### Contoh Brewfile

```
# ~/Brewfile
tap "homebrew/bundle"
brew "git"
brew "node"
brew "python"
cask "visual-studio-code"
cask "docker"
```
