Fast install and correct setup for Homebrew on Mac

Step 1 — Use your Terminal!
Like any other application, you can find it by going into Finder, navigating to the Applications
folder, and then into the Utilities
folder. From here, double-click the Terminal application to open it up. Alternatively, you can use Spotlight by holding down the COMMAND
key and pressing SPACE
to find Terminal by typing it out in the box that appears.
Now that you have the Terminal running, let’s install some additional tools Homebrew needs.
Step 2— Installing Xcode’s Command Line Tools
xcode-select — install
You’ll be prompted to start the installation and then again to accept a software license. Then the tools will download and install automatically.
Step 3 — Installing Homebrew
curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
The command uses curl
to download the Homebrew installation script from Homebrew’s Git repository on GitHub.
Let’s walk through the flags that are associated with the curl
command:
- The -
f
or--fail
the flag tells the Terminal window to give no HTML document output on server errors. - The
-s
or--silent
flag mutescurl
so that it does not show the progress meter, and combined with the-S
or--show-error
flag it will ensure thatcurl
shows an error message if it fails. - The
-L
or--location
flag will tellcurl
To handle redirects. If the server reports that the requested page has moved to a different location, it’ll automatically execute the request again using the new location. - The
-o
switch specifies a local filename for the file. Rather than displaying the contents to the screen, the-o
switch saves the contents into the file you specify.
Before running a script you’ve downloaded from the Internet, you should review its contents to know what the script will do. Use the less
command to review the installation script, so you understand what it will do."
less install.sh
Once you’re comfortable with the contents of the script, execute the script with the bash
command
/bin/bash install.sh
The installation script will explain what it will do and prompt you to confirm that you want to do it.
Once the installation process is complete, you will want to put the directory Homebrew uses to store its executables at the front of the PATH
environment variable. This ensures that Homebrew installations will be called over the macOS tools.
The file you’ll modify depends on which shell you’re using. ZSH is the default shell on macOS Mojave and higher. The Bash shell is a popular shell that older versions of macOS use as the default, and if you’ve upgraded your OS, you may still be using Bash.
Execute the following command to determine your shell
echo $0
You’ll see either bash
or zsh
. If you’re using ZSH, you’ll open the file ~/.zshrc
in your editor
nano ~/.zshrc
f you’re using the Bash shell
nano ~/.bash_profile# Add Homebrew's executable directory to the front of the PATH
export PATH=/usr/local/bin:$PATH
Reload your Shell or Restart your Terminal to get the updated config.
Once you have done this, your changes to the PATH
environment variable will take effect. They’ll be set correctly when you log in again in the future, as the configuration file for your shell is executed automatically when you open the Terminal app.
Now let’s verify that Homebrew is set up correctly
brew doctor
Step 4 — Installing, Upgrading, and Removing Packages
Install tree
with the brew install
command
brew install tree
Homebrew will update its list of packages and then download and install the tree
command
Homebrew installs files to /usr/local
by default, so they won’t interfere with future macOS updates. Verify that tree
is installed by displaying the command’s location with the which
command
which tree
The output should show that tree
is located in /usr/local/bin
Run the tree
command to see the version
tree — version
If you want to upgrade an existing package, use the brew upgrade command followed by the package name
brew upgrade tree
To remove a package you’re no longer using, use brew uninstall
. To uninstall the tree
command, execute this command
brew uninstall tree
Step 5 — Installing Desktop Applications
Homebrew Cask lets you install desktop applications. This feature is included with Homebrew, so there’s nothing additional to install.
Please test it out by using Homebrew to install Visual Studio Code
brew install visual-studio-code
You’ll find the application in your Applications
folder, just as if you’d installed it manually. To remove it, just use
brew uninstall visual-studio-code
Step 6 — Uninstalling Homebrew
I don’t know why you ever wanted to uninstall homebrew, but follow these simple steps if you want to do it.
Download the uninstall script
curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
As always, review the contents of the script with the less
command to verify the script’s contents
less uninstall.sh
If everything is okay, then watch the options for the uninstall script
bash uninstall.sh --help
Use the -d
flag to see what the script will do
bash uninstall.sh -d
When you’re ready to remove everything, execute the script without any flags
bash uninstall.sh
This removes Homebrew and any programs you’ve installed with it
Visit the official list to search for your favorite programs.
Step 7 — Setting Up Homebrew Shell Completion
Homebrew comes with completion definitions for the brew
command. Some packages also provide completion definitions for their own programs.
zsh
, bash
and fish
are currently supported.
You must manually configure your shell to enable its complete support. This is because the Homebrew-managed completions are stored under HOMEBREW_PREFIX
which your system shell may not be aware of, and since it is difficult to configure automatically bash
and zsh
completions in a robust manner, the Homebrew installer does not do it for you.
To make Homebrew’s completions available in zsh
You must insert the Homebrew-managed zsh/site-functions
path into your FPATH
before initializing zsh
’s completion facility. Add the following to your ~/.zshrc
if type brew &>/dev/null
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
autoload -Uz compinit
compinit
fi
You may also need to rebuild forcibly zcompdump (or any file like zcondump-5.14)
rm -f ~/.zcompdump
After you deleted all the files, just
compinit
You find the complete help documentation for all shells provided via https://docs.brew.sh/Shell-Completion
Use the interactive Homebrew shell
brew irb
Hide the beer mug emoji
adding this line to your shell config
export HOMEBREW_NO_EMOJI=1
The beer emoji can also be replaced with other characters
export HOMEBREW_INSTALL_BADGE="☕️ 🐸"
Install stuff without the Xcode CLT
brew sh # or: eval "$(brew --env)"
gem install ronn # or c-programs
Quickly remove something from Homebrew
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 afterward!
Using Brewfile to automatic setup
The bundle is automatically installed once it is used
brew bundle dump
Dumps latest Brewfile into current Directory. This Brewfile lists all your installed programs via Homebrew. If you want to restore all your programs or install all your needed programs automatically on a fresh machine, just
brew bundle --file ~/your-path-to-your/Brewfile
And Homebrew is setting up everything
Fast way to clean up cache and unused files and data, update programs and remove the old versions from your Mac.
Just use this command and paste it into your Terminal
brew update && brew upgrade && brew cleanup
Conclusion
You can install, update, reinstall, backup, secure, and clean your mac and your programs easily and fast with homebrew and your terminal.