# Homebrew
### [Install Homebrew on macOS](https://brew.sh/)
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
### [Install Homebrew on Ubuntu or Debian](https://docs.brew.sh/Homebrew-on-Linux)
```bash
sudo apt-get install build-essential procps curl file git
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
#### Relic: `/home/linuxbrew/.linuxbrew/bin` must be in `PATH`
```bash
# Use tee to add the following line to local.sh
echo 'export PATH="$PATH:/home/linuxbrew/.linuxbrew/bin"' | tee -a ~/env/local.sh
# Refresh shell
source ~/.zshrc
# Confirm linuxbrew is in path
echo $PATH
```
### Homebrew services
Output of `homebrew services --help`:
```bash
$ homebrew services --help
Usage: brew services [subcommand]
Manage background services with macOS' launchctl(1) daemon manager.
If sudo is passed, operate on /Library/LaunchDaemons (started at boot).
Otherwise, operate on ~/Library/LaunchAgents (started at login).
[sudo] brew services [list] (--json):
List information about all managed services for the current user (or root).
[sudo] brew services info (formula|--all|--json):
List all managed services for the current user (or root).
[sudo] brew services run (formula|--all):
Run the service formula without registering to launch at login (or boot).
[sudo] brew services start (formula|--all|--file=):
Start the service formula immediately and register it to launch at login
(or boot).
[sudo] brew services stop (formula|--all):
Stop the service formula immediately and unregister it from launching at
login (or boot).
[sudo] brew services kill (formula|--all):
Stop the service formula immediately but keep it registered to launch at
login (or boot).
[sudo] brew services restart (formula|--all):
Stop (if necessary) and start the service formula immediately and register
it to launch at login (or boot).
```
## Notes
### Install a specific older version that isn't available locally
[This Stack Overflow answer](https://stackoverflow.com/a/46306176) is a godsend
Replace all occurrences of `memcached` with the brew package of interest, e.g. `rust-analyzer`.
> Usually, you can check if multiple versions are available and you can specify the version with @. e.g. brew install
[email protected]
```bash
$ brew info memcached
memcached: stable 1.4.24
High performance, distributed memory object caching system
https://memcached.org/
Conflicts with:
mysql-cluster (because both install `bin/memcached`)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/memcached.rb
...
```
If is not available the version you want you can go to the repo, and check the history
```bash
cd "$(brew --repo homebrew/core)"
git log master -- Formula/memcached.rb
```
Then you can find the commit you are looking for
```bash
commit 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
Author: Adam Vandenberg <
[email protected]>
Date: Fri Apr 9 21:19:48 2010 -0700
Update memcached to 1.4.5
```
Checkout that version and install:
```bash
cd "$(brew --repo homebrew/core)" && git checkout 5ec463decefeaab3d1825b923ad2dbee73ffc6dc
HOMEBREW_NO_AUTO_UPDATE=1 brew install memcached
```
Once you get the version installed:
```bash
git checkout master # bring brew back to its latest version
brew pin memcached # [optional] prevent formula from updating
```
### `brew --prefix` difference between Intel and Apple Silicon Macs
The output of:
```bash
echo $(brew --prefix)
```
Is:
- `/usr/local` on x86 / Intel Macs
- `/opt/homebrew` on M1 / Apple Silicon Macs
So referencing brew dependencies via `$PATH` will be different on the two platforms.