# Homebrew Riferimento Rapido

*Gestione pacchetti, cask, tap, servizi, pulizia*

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

## Installazione

### Installa Homebrew

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

### Post-Installazione (Apple Silicon)

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

### Percorsi di Installazione

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

## Gestione Pacchetti

### Installazione e Rimozione

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

### Aggiornamento

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

### Elenco Installati

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

## Ricerca e Info

### Ricerca Pacchetti

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

### Campi Info

| Command | Description |
|---------|-------------|
| `Name / Version` | Nome del pacchetto e versione installata |
| `Dependencies` | Pacchetti richiesti |
| `Conflicts` | Pacchetti incompatibili |
| `Caveats` | Note post-installazione (PATH, config) |
| `Analytics` | Conteggio installazioni (ultimi 30/90/365 giorni) |

## Servizi

### Gestione Servizi

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

### Note sui Servizi

| Command | Description |
|---------|-------------|
| `start` | Avvia subito + registra all'avvio |
| `run` | Avvia subito soltanto (senza auto-start) |
| `stop` | Ferma e deregistra dall'avvio |
| `restart` | Ferma poi avvia |
| `list` | Mostra tutti i servizi e il loro stato |
| `Logs` | Controlla `~/Library/Logs/Homebrew/` |

## Cask

### Gestione Applicazioni 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 Comuni

| Command | Description |
|---------|-------------|
| `google-chrome` | Browser Chrome |
| `visual-studio-code` | Editor VS Code |
| `docker` | Docker Desktop |
| `iterm2` | Terminale iTerm2 |
| `slack` | Messaggistica Slack |
| `rectangle` | Gestione finestre |
| `1password` | Gestore password |
| `raycast` | Launcher (sostituto di Spotlight) |

## Tap

### Repository di Terze Parti

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

| Command | Description |
|---------|-------------|
| `homebrew/cask` | App GUI (inclusa per default) |
| `homebrew/cask-fonts` | Font: `brew install --cask font-fira-code` |
| `homebrew/bundle` | Supporto Brewfile (Bundler per 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
```

## Pulizia

### Liberare Spazio su 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
```

### Diagnostica

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

## Pattern Comuni

### Flussi di Lavoro Quotidiani

| Command | Description |
|---------|-------------|
| `Aggiornamento mattutino` | `brew update && brew upgrade && brew cleanup` |
| `Configurazione nuovo Mac` | `brew bundle install` da un Brewfile |
| `Esporta configurazione` | `brew bundle dump --file=~/Brewfile` |
| `Controlla salute` | `brew doctor` |
| `Trova cosa occupa spazio` | `brew list --formula \| xargs brew info` |
| `Disinstalla + dipendenze` | `brew uninstall pkg && brew autoremove` |

### Esempio di Brewfile

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