brew/docs/Tips-N'-Tricks.md

107 lines
4.2 KiB
Markdown
Raw Normal View History

# Tips and Tricks
2021-11-14 21:13:07 -05:00
## Install previous versions of formulae
2015-08-28 09:10:10 -07:00
2021-11-14 21:13:07 -05:00
Some formulae in `homebrew/core` are made available as [versioned formulae](Versions.md) using a special naming format, e.g. `gcc@7`. If the version you're looking for isn't available, consider using `brew extract`.
## Quickly remove something from Homebrew's prefix
2015-08-28 09:10:10 -07:00
```sh
brew unlink <formula>
```
This can be useful if a package can't build against the version of something you have linked into Homebrew's prefix.
And of course, you can simply `brew link <formula>` again afterwards!
2021-11-14 21:13:07 -05:00
## Pre-download a file for a formula
2021-08-06 12:52:36 -04:00
2021-11-14 21:13:07 -05:00
Sometimes it's faster to download a file via means other than the strategies that are available as part of Homebrew. For example, Erlang provides a torrent that'll let you download at 45× compared to the normal HTTP method.
Downloads are saved in the `downloads` subdirectory of Homebrew's cache directory (as specified by `brew --cache`, e.g. `~/Library/Caches/Homebrew`) and renamed as `<url-hash>--<formula>-<version>`. The command `brew --cache --build-from-source <formula>` will print the expected path of the cached download, so after downloading the file, you can run `mv the_tarball "$(brew --cache --build-from-source <formula>)"` to relocate it to the cache.
You can also pre-cache the download by using the command `brew fetch <formula>` which also displays the SHA-256 hash. This can be useful for updating formulae to new versions.
2021-11-14 21:13:07 -05:00
## Install stuff without the Xcode CLT
2015-08-28 09:10:10 -07:00
```sh
brew sh # or: eval "$(brew --env)"
gem install ronn # or c-programs
```
2021-11-14 21:13:07 -05:00
This imports the `brew` environment into your existing shell; `gem` will pick up the environment variables and be able to build. As a bonus, `brew`'s automatically determined optimization flags are set.
## Install only a formula's dependencies (not the formula)
2015-08-28 09:10:10 -07:00
```sh
brew install --only-dependencies <formula>
```
2021-11-14 21:13:07 -05:00
## Use the interactive Homebrew shell
```console
$ brew irb
2021-11-14 21:13:07 -05:00
==> Interactive Homebrew Shell
Example commands available with: `brew irb --examples`
irb(main):001:0> Formulary.factory("ace").methods - Object.methods
=> [:install, :test, :test_defined?, :sbin, :pkgshare, :elisp,
:frameworks, :kext_prefix, :any_version_installed?, :etc, :pkgetc,
...
:on_macos, :on_linux, :debug?, :quiet?, :verbose?, :with_context]
irb(main):002:0>
```
2021-11-14 21:13:07 -05:00
## Hide the beer mug emoji when finishing a build
2015-08-28 09:10:10 -07:00
```sh
export HOMEBREW_NO_EMOJI=1
```
2021-11-14 21:13:07 -05:00
This sets the `HOMEBREW_NO_EMOJI` environment variable, causing Homebrew to hide all emoji.
The beer emoji can also be replaced with other character(s):
2015-08-28 09:10:10 -07:00
```sh
export HOMEBREW_INSTALL_BADGE="☕️ 🐸"
```
## Migrate a Homebrew installation to a new location
Running `brew bundle dump` will record an installation to a `Brewfile` and `brew bundle install` will install from a `Brewfile`. See `brew bundle --help` for more details.
## Appoint Homebrew Cask to manage a manually-installed app
Run `brew install --cask` with the `--adopt` switch:
```console
$ brew install --cask --adopt textmate
==> Downloading https://github.com/textmate/textmate/releases/download/v2.0.23/TextMate_2.0.23.tbz
...
==> Installing Cask textmate
==> Adopting existing App at '/Applications/TextMate.app'
==> Linking Binary 'mate' to '/opt/homebrew/bin/mate'
🍺 textmate was successfully installed!
```
## Editor plugins
### Visual Studio Code
- [Brewfile](https://marketplace.visualstudio.com/items?itemName=sharat.vscode-brewfile) adds Ruby syntax highlighting for [Homebrew Bundle](https://github.com/Homebrew/homebrew-bundle) `Brewfile`s.
- [Brew Services](https://marketplace.visualstudio.com/items?itemName=beauallison.brew-services) is an extension for starting and stopping Homebrew services.
### Sublime Text
2021-11-14 21:13:07 -05:00
- [Homebrew-formula-syntax](https://github.com/samueljohn/Homebrew-formula-syntax) can be installed with Package Control in Sublime Text 2/3, which adds highlighting for inline patches.
### Vim
2021-08-06 12:52:36 -04:00
2021-11-14 21:13:07 -05:00
- [brew.vim](https://github.com/xu-cheng/brew.vim) adds highlighting to inline patches in Vim.
### Emacs
2021-08-06 12:52:36 -04:00
2021-11-14 21:13:07 -05:00
- [homebrew-mode](https://github.com/dunn/homebrew-mode) provides syntax highlighting for inline patches as well as a number of helper functions for editing formula files.
2016-08-15 18:41:22 -05:00
2021-11-14 21:13:07 -05:00
- [pcmpl-homebrew](https://github.com/hiddenlotus/pcmpl-homebrew) provides completion for emacs shell-mode and eshell-mode.