How to Install Homebrew on macOS? (Step-by-Step Guide: Install Homebrew macOS )
The command-line interface (CLI) is a text-based tool for interacting with your computer. It allows you to automate tasks by typing commands instead of using a mouse. While macOS shares many CLI features with Unix systems, it lacks a built-in package manager, which simplifies installing, updating, and managing software by keeping everything organized in one place.
What is Homebrew?
Homebrew is a popular package manager designed formacOS (and Linux) that simplifiesinstalling, updating, and managing software tools and applications. Users can access a wide range of utilities with just one command, streamlining the process of setting up and maintaining software on their systems. It has become an essential tool for developers and tech enthusiasts, enabling efficient software deployment.
Why Use Homebrew?
Homebrew grants access to open-source software, including development tools, utilities, productivity applications, and even games. It provides macOS users with options far beyond what’s available in the App Store, making it an invaluable resource for expanding functionality. By operating directly from the command line, Homebrew makes it easy to install and maintain a comprehensive development environment.
This tool caters to a diverse audience, from developers to casual users. Homebrew offers an extensive library of options, whether you're looking for software to edit videos, create music, design graphics, or automate tasks like file management and system configuration. With countless packages available, the possibilities are nearly endless.
However, keep in mind that Homebrew operates through the terminal, so having a basic understanding of command-line interfaces is recommended for smooth usage.
This guide will walk you through installing Homebrew on macOS, introduce some commonly used commands, and explain how to uninstall it when necessary. Let's dive in!
Prerequisites
To install Homebrew on macOS, you’ll need to require the following prerequisites:
- A macOS computer running Catalina or later.
- Administrative privileges to access the system.
- An active internet connection.
Note: Older macOS versions may work but are not officially supported.
How to Install Homebrew on macOS? (Install Homebrew macOS)
You can install Homebrew on macOS by performing the following steps:
Step 1: Access macOS Terminal
To access the command line on your Mac, open the Terminal app included with macOS. You can find it in Finder by going to the Applications folder, then the Utilities folder, and double-clicking on Terminal. Alternatively, use Spotlight by pressing COMMAND + SPACE, typing "Terminal," and selecting it from the search results.
With Terminal open, the next step is to install some tools required for Homebrew.
Step 2: Install Xcode Command Line Tools
Xcode is an IDE that provides development tools for macOS. While you don’t need the full Xcode app for Homebrew, many of the packages and components you might use will depend on Xcode’s Command Line Tools.
Run the following command in Terminal to download and install the necessary tools:
$ xcode-select --install
Follow the prompts to begin the installation and accept the software license. The tools will then download and install automatically.
Once the installation is complete, you’re ready to proceed with installing Homebrew.
Step 3: Download Homebrew Installation Script (Download Homebrew on macOS)
To install Homebrew, you’ll need to download Homebrew on macOS. For this purpose, we’ll download the homebrew installation script and then run it.
Start by downloading the script to your computer with the following command in the Terminal:
$ curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
This command uses curl to fetch the Homebrew installation script from its official GitHub repository.
Here’s a breakdown of the curl flags used:
- -f or --fail: Ensures no HTML output is shown in case of server errors.
- -s or --silent: Suppresses the progress meter, making the output cleaner.
- -S or --show-error: Displays error messages if the command fails.
- -L or --location: Automatically follows redirects if the file has moved to a new URL.
- -o: Saves the downloaded file to a specified name instead of showing its content in the terminal.
This will save the script locally under the name install.sh, and you can proceed to execute it to complete the Homebrew installation.
Step 4: Run the Homebrew Installation Script (Install brew on macOS)
Before running any downloaded script, it’s important to review its contents to ensure you understand what it will do. To inspect the Homebrew installation script, use the less command:
$ less install.sh
Once you’re confident in the script’s contents, you can run it using the following command:
$ /bin/bash install.sh
The installation script will provide an overview of what it will do and ask for your confirmation before proceeding. This ensures you understand the changes it will make to your system and verifies that your system meets all prerequisites.
During the installation, you’ll be asked to enter your password. Note that your password will not appear as you type it in the Terminal—that’s a security feature. Just press RETURN after entering your password.
Whenever prompted to confirm the installation, press y for "yes" to proceed.
Step 5: Add Homebrew to System’s PATH
After completing the installation, you need to add Homebrew's executable directory to the front of your system’s PATH. This ensures that Homebrew’s tools are prioritized over macOS’s default tools.
To determine which shell you're using, run:
$ echo $0
If you see bash, you're using the Bash shell; if you see zsh, you're using the Zsh shell (default for macOS Mojave and later).
If you're using Zsh, edit the ~/.zshrc file:
$ nano ~/.zshrc
If you're using Bash, edit the ~/.bash_profile file:
$ nano ~/.bash_profile
In the file, add the following line at the end:
# Add Homebrew's executable directory to the front of the PATH export PATH=/usr/local/bin:$PATH
To save the changes, press CTRL + O, then RETURN. To exit the editor, press CTRL + X.
To apply the changes, either restart the Terminal or use the source command:
If you are using Zsh, run:
source ~/.zshrc
If you are using Bash, run:
source ~/.bash_profile
This will make sure Homebrew is properly set up and its tools are accessible from the command line.
Step 6: Verify Homebrew Installation
After making the changes to your PATH, they will be applied automatically the next time you open Terminal. To verify Homebrew is set up correctly, run:
$ brew doctor
If everything is working fine, you’ll see the message in the terminal “Your system is ready to brew”.
If there are any issues, you may be prompted to run brew update or another command to update Homebrew. Follow the on-screen instructions to resolve any issues before proceeding.
Installing, Upgrading, and Removing Packages with Homebrew
Once Homebrew is installed, you can use it to manage software packages. For example, to install the tree command (which displays a directory tree), run:
brew install tree
Homebrew will download and install the package. To verify the installation, use:
which tree
This should show the path where the tree is installed, typically /usr/local/bin/tree. You can also check the version with:
tree --version
To upgrade an installed package, use:
brew upgrade tree
To upgrade all installed packages, run brew upgrade without specifying a package name. If you want to remove old versions and free up disk space, use:
brew cleanup
To uninstall a package you no longer need, like tree, run:
brew uninstall tree
Homebrew can also be used to install desktop applications.
Installing and Uninstalling Desktop Applications with Homebrew
Homebrew Cask allows you to install desktop applications along with command-line tools. You don’t need to install anything extra to use this feature, as it's included with Homebrew.
To install an application like Visual Studio Code, run the following command in your terminal:
brew install visual-studio-code
This will download and install the application. You’ll find Visual Studio Code in your Applications folder, and the code binary will be linked to /usr/local/bin/code.
To uninstall the application, run:
brew uninstall visual-studio-code
Homebrew will first back up the application in case the removal fails. Once the application has been successfully uninstalled, it will remove the backup and all related files.
How to Uninstall Homebrew from macOS?
If you wish to remove Homebrew from your system, you can use its uninstall script.
First, download the uninstall script using curl:
curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
Before running the script, it's a good idea to review its contents. Use the less command to check the script:
less uninstall.sh
You can see all available options for the script by running it with the --help flag:
bash uninstall.sh --help
This will display options such as:
- -p to set the Homebrew prefix
- -f to uninstall without prompting
- -q to suppress output
- -d to simulate the uninstallation
- -h to display help
If you want to see what the script will delete before running it, use the -d flag:
bash uninstall.sh -d
This will list everything that would be removed, so you can review it before proceeding.
When you're ready, execute the script without any flags to completely uninstall Homebrew and all programs installed via it:
bash uninstall.sh
This will remove Homebrew and any associated software.
Conclusion
In this guide, we learned how to install Homebrew on macOS. Now, the question is, what is Homebrew? With Homebrew set up, you can easily install various command-line tools, programming languages, and utilities essential for software development.
Homebrew offers a wide selection of packages. Explore the official homebrew packages list to find and install your preferred programs.
Are you looking for a robust hosting plan for your websites? Unlock the potential of unlimited hosting with 10GBVPS! Enjoy blazing-fast speeds that enhance your website's performance, ensuring a seamless user experience. Say goodbye to the stress of bandwidth limits and unexpected overage fees. With a variety of global locations to choose from, you can ensure optimal speed and reliability for your website, no matter where your audience is located.
Blog