# Referência Rápida Homebrew

*Gerenciamento de pacotes, casks, taps, serviços, limpeza*

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

## Instalação

### Instalar Homebrew

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

### Pós-Instalação (Apple Silicon)

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

### Caminhos de Instalação

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

## Gerenciamento de Pacotes

### Instalar e Remover

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

### Atualizar

```
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
```

### Listar Instalados

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

## Busca e Informação

### Encontrar Pacotes

```
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
```

### Campos de Informação

| Command | Description |
|---------|-------------|
| `Name / Version` | Nome e versão instalada do pacote |
| `Dependencies` | Pacotes necessários |
| `Conflicts` | Pacotes que não podem coexistir |
| `Caveats` | Notas pós-instalação (PATH, config) |
| `Analytics` | Contagem de instalações (últimos 30/90/365 dias) |

## Serviços

### Gerenciando Serviços

```
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
```

### Notas sobre Serviços

| Command | Description |
|---------|-------------|
| `start` | Iniciar agora + registrar na inicialização do login |
| `run` | Iniciar agora apenas (sem auto-start) |
| `stop` | Parar e desregistrar da inicialização |
| `restart` | Parar e depois iniciar |
| `list` | Mostrar todos os serviços e seus status |
| `Logs` | Verificar `~/Library/Logs/Homebrew/` |

## Casks

### Gerenciamento de Aplicativos 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
```

### Casks Comuns

| Command | Description |
|---------|-------------|
| `google-chrome` | Navegador Chrome |
| `visual-studio-code` | Editor VS Code |
| `docker` | Docker Desktop |
| `iterm2` | Terminal iTerm2 |
| `slack` | Mensagens Slack |
| `rectangle` | Gerenciamento de janelas |
| `1password` | Gerenciador de senhas |
| `raycast` | Launcher (substituto do Spotlight) |

## Taps

### Repositórios de Terceiros

```
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
```

### Taps Populares

| Command | Description |
|---------|-------------|
| `homebrew/cask` | Apps GUI (incluído por padrão) |
| `homebrew/cask-fonts` | Fontes: `brew install --cask font-fira-code` |
| `homebrew/bundle` | Suporte a Brewfile (Bundler para 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
```

## Limpeza

### Liberando Espaço em Disco

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

### Diagnósticos

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

## Padrões Comuns

### Fluxos de Trabalho do Dia a Dia

| Command | Description |
|---------|-------------|
| `Morning update` | `brew update && brew upgrade && brew cleanup` |
| `New Mac setup` | `brew bundle install` a partir de um Brewfile |
| `Export setup` | `brew bundle dump --file=~/Brewfile` |
| `Check health` | `brew doctor` |
| `Find what uses space` | `brew list --formula \| xargs brew info` |
| `Uninstall + deps` | `brew uninstall pkg && brew autoremove` |

### Exemplo de Brewfile

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