If you ever wondered how to install command-line tools such as telnet, cask, htop, wget, nmap, etc, on macOS? or do you need a package manager on macOS to install and update your favorite applications?
For you as a developer or sysadmin, Homebrew enables you to install your needs that macOS didn’t include in its core OS.
What is Homebrew?
Homebrew (brew) is a free and open-source package manager that allows installing apps and software on macOS, depending on the user’s desire. It has been recommended for its simplicity and effectiveness in saving time and effort. Its famous description is “The missing package manager for macOS”.
It’s really legendary to get the power of using the latest and updated version of software on your Mac device. In Homebrew, there are formulae packages to directly install from its core public repository. In addition, there is the cask (brew-cask) which is an extension to enrich you with more software packages and binary apps using the command line.
If you want to know some benefit examples of using Homebrew from what experts said, read the following:
- Collect all your variety of different libraries and software packages into one place.
- Automate your work throw getting benefits from thousands of command-line-based tools.
- Install and learn practical Python scripts on your local Mac computer.
- Setup a testing and development environment for your software development.
- Install many not-available apps at the App Store.
Homebrew put installations files at the user path /usr/local/bin/
, or in the file system in /usr/local/Cellar
, but links them into /usr/local/bin
. This facilitates for you to launch these apps from the applications folder as if it is a usual part of your lovely macOS.
System Requirements
Installing Homebrew needs some system requirements and personal familiarity skills in the macOS Terminal, which you will use to install Homebrew. And before that, you should install Apple’s Xcode development software which some Homebrew packages need as a dependency.
The minimum specifications you need to install Homebrew on a Mac are the following:
- macOS Mojave (10.14) or later, the previous versions are limited supported.
- Apple Silicon CPU 1, or a 64-bit Intel CPU.
- Command Line Tool (CLT) for Xcode.
- Availability and knowledge of the bourne-compatible shell for installation and using bash or zsh.
- Internet connection and administrative access.
Installing Homebrew
It’s a relatively easy process if you are familiar with using a command line, there are some little different methods, but mostly similar to each other:
Open the Mac OS Terminal
Find macOS Terminal interface by the Finder, then the Application folder, down to the Utility folder, double-click the Terminal application icon.
Or you can simply use the key shortcut, hold down COMMAND + SPACE, and type “Terminal” at the box.
Install Xcode’s Command Line Tools
You need Xcode for some Homebrew tools, Xcode is a macOS integrated development environment (IDE). You can use it to make apps for all mac OSs, iOS, iPad OS, watch OS, and tv OS. To download and install it, run the following command in the Terminal:
xcode-select --install
Accept starting the installation and the license, it will be installed automatically.
Install Homebrew
Now, to install Homebrew automatically, run the below command for macOS High Sierra, Sierra, El Capitan, and earlier:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
If you like to see the series lines of installing the script press Return
, press it for the second time to accept installing, or press Escape
for canceling. You will be asked to enter the admin password. Then wait for some time until the process finishes, you will see the message “Installation successful!”.
To install Homebrew in a manual way, you can write a command to download the installation script, and then write another command to execute the script.
Run the following command in the terminal shell to download the script:
curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/master/install.sh
This curl command will download the Homebrew installation script from Homebrew’s Git repository to your mac machine, but without installing it.
Now, the benefit of the manual method is that you can review its code if you like to know the script which will execute. Now write the less command to take an idea:
less install.sh
If you feel comfortable with the script contents, install them by the bash command:
/bin/bash install.sh
The script will show you its order process and will ask you to accept it. The script will also verify the computer prerequisites before going on. When it prompted your super password, enter it, and enter the letter Y to finally confirm your acceptance of the installation process.
At this point, in order to congratulate yourself, you may prefer to run a command that let make sure that the Homebrew installed truly:
brew doctor
The result will tell you about the Homebrew status and if any packages need updates.
If all things are OK, you should see this message:
<span style="color: #999999;">Output</span>
Your system is ready to brew.
When you reach this point, finally you can start installing software packages via Homebrew, run the help documentation to have more information:
brew help
You can also search for apps using the command brew search {package name}
Example
brew search nginx
Turn off Analytics
Homebrew collects user data and sends analytics to the developers using anonymized behavioral tracking, you may have no problem with that, or you prefer to disable it.
If you want to disable analytics, enter this command:
brew analytics off
Install Packages
You can now install, upgrade, and remove your favorite packages, it’s recommended to start with the tree
package, it allows you have a graphical directory tree. You can install it using below command.
brew install tree
This command will update the Homebrew packages list, then install the tree command.
To update all formulae software and brew, enter:
brew update
Homebrew supposed to installs packages files to /usr/local by default, to see the path of any installed package with the which command:
which {package name}
The result should be:
<span style="color: #999999;">Output</span>
/usr/local/bin/{package name}
To uninstall a package, write this command:
brew uninstall {package name}
Examples of Installing Software Using Homebrew
There are thousands of software packages in formulae of Homebrew, such as:
imagemick: a tool to manipulate images to other formats for macOS.
Installing command:
brew install imagemagick
archey: graphical system information to share the localhost with your team for macOS.
Installing command:
brew install archey
hub: to add GitHub support a better experience the command-line.
Installing command:
brew install hub
tldr: to have simplified examples on how to use the command line, with community-driven man pages.
Installing command:
brew install tldr
Homebrew Casks
Cask is another collection of homebrew packages from macOS apps and non-open source software. To search for a package, enter brew search –casks {package name}:
brew search --casks google-chrome
brew search --casks docker
brew search --casks dropbox
For installing a cask software, use the command brew install --cask {package name}
Example
brew install --cask firefox
Uninstalling Homebrew
Uninstalling Homebrew is a very simple process, you just need to execute the uninstall ruby script in the terminal, just choose the command that aligns your MacOS version.
For uninstalling Homebrew from macOS Catalina, macOS Big Sur, and macOS Mojave, enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
For uninstalling Homebrew from macOS High Sierra, Sierra, El Capitan, and earlier, enter:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Or you can download the “uninstall” script to your machine and run it manually:
curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
After reviewing the script contents, run this script to uninstall Homebrew:
bash uninstall.sh
Conclusion
In this tutorial, you can have a clear idea that supported by codes, details, and examples to install Homebrew on your macOS. For more details, you can see the official list of Homebrew packages.
Enjoy!