How to Install Homebrew on Mac
The command line is an option for communicating with a computer system without a graphical interface. Instead of clicking on buttons in an interface, the user enters text commands and receives feedback in the same form. Despite the predominance of graphical interfaces, working with the command line continues to be supported by all operating systems. It is used primarily by software developers and system administrators.
This statement is also true for macOS, where it is possible to install additional modules, such as a package manager. A package manager automates software installation, update, and configuration. Such programs support popular file formats and store installed programs in centralized storage.
In this article, we will examine Homebrew, a package manager for macOS that is often used to work with Python, Ruby, Node.js, and other open-source software. We will describe how to install Homebrew on MacOS and use the basic commands for managing packages.
Prerequisites Copy link
- Any computer or laptop running macOS Catalina or a newer version installed (older versions might still be compatible)
- Administrator privileges
- Internet connection
How to Use the Terminal on macOS Copy link
The terminal is preinstalled on macOS systems. To access it, you can use search or go to the Utilities folder located in Applications. Double-click on it to launch the utility.
Yet another launch option is through Spotlight, in which you just need to press Space+Command and enter the word Terminal.
That's it, the terminal is launched, and you can explore the Homebrew tool for macOS.
Installing Xcode Command Line Tools Copy link
The Xcode integrated development environment (IDE) is popular among macOS software developers. It is not required for Homebrew to function, but some of the components are quite useful. Therefore, let's install the package with the command:
xcode-select -installDuring the installation process, you will be asked to accept the license. Do that, and the installation will continue. The system will automatically download the necessary files and install them. Now, you can get started with Homebrew on MacOS.
Installing and configuring Homebrew Copy link
So, let’s get to installing Homebrew on Mac.
First, you must download and execute the script with the following command:
curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/master/install.shIt uses flags:
-
-
for-failprohibits the output of information in case of a server error; -
-sor-silentdeactivates the progress indicator; -
-Sor-show-errorenables the display of an error message if the installation fails; -
-Lor-locationenables automatic redirection when the location changes; -
-osets the file name for local storage.
Before running the script, you can view its contents:
less install.shThen run it:
/bin/bash install.shThe script will show information about every step and prompt you to confirm actions (by pressing the Y key). This approach allows you to ensure that all the necessary modules have been installed.
Also during the process, the system will prompt you to enter a password. Please note that, as a security measure, it will not be displayed in the terminal while typing it, so be careful.
Once completed, you will need to place the folder with the executables in the PATH environment variable. The directory can differ: on ARM systems, they're installed to /opt/homebrew, on Intel, to /usr/local/Homebrew.
The file that you need to edit depends on the shell. With Bash, the command is going to be:
nano ~/.bash_profileIf ZSH is used, the editing command will look like:
nano ~/.zshrcAdd the following lines to the file, at the very end.
For Intel:
# Adding Homebrew's executable directory to the front of the PATH
export PATH=/usr/local/bin:$PATHFor ARM:
export PATH=/opt/homebrew/bin:$PATHTo save the changes, use the key combination Ctrl + O, then press Return, To exit the editor, press Ctrl + X. You will return to the terminal.
To apply the changes, you can restart the terminal or use the command below. For Bash, it will look like this:
source ~/.bash_profileFor ZSH:
source ~/.zshrcTo make sure that Homebrew is installed correctly, you can use the command:
brew doctorIf everything works as it should, you will see the message:
Your system is ready to brewInstalling, updating, and removing packages Copy link
Now you can use Homebrew to manage packages.
For example, let's install the tree package to view a graphical directory tree.
brew install treeThe application will automatically update the list of packages and install tree. You will see a similar message on the screen:
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/tree-1.8.0.catalina.bottle.tar.gz
The default installation path is the /usr/local directory. This way, the files do not interfere with the installation of operating system updates.
You can verify that the tree package is available on your computer using the command:
which treeThe system shows the directory in use:
/usr/local/bin/treeTo check the version of the application, use:
tree -versionThe screen output will look like this:
tree v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke TokoroIf the version is outdated, you can upgrade the package:
brew upgrade treeIt is important to note that the package manager keeps old file versions, which take up storage space. To remove unnecessary copies, use the cleanup command:
brew cleanupIf you no longer need the tree package, you can uninstall it from your computer:
brew uninstall treeInstalling desktop applications Copy link
The Homebrew Cask package manager can also install desktop applications. This functionality is built into the utility, so there is no need to install anything additional. As an example, let's install Visual Studio Code.
brew install visual-studio-codeYou should see a similar message on the screen:
==> Downloading https://update.code.visualstudio.com/1.58.2/darwin/stable
==> Downloading from https://az764295.vo.msecnd.net/stable/a0479759d6e9ea56afa657e454193f72aef85bd0/VSC
################################################## ###################### 100.0%
==> Verifying SHA-256 checksum for Cask 'visual-studio-code'.
==> Installing Cask visual-studio-code
==> Moving App' Visual Studio Code.app' to '/Applications/Visual Studio Code.app'.
==> Linking Binary' code' to '/usr/local/bin/code'.
visual-studio-code was successfully installed!Once the procedure is complete, the application will appear in the Application directory. To remove software that is no longer needed, use the command:
brew uninstall visual-studio-codeThe system will confirm its completion with the message:
==> Backing App' Visual Studio Code.app' up to '/usr/local/Caskroom/visual-studio-code/1.58.2/Visual Studio Code.app'
==> Removing App '/Applications/Visual Studio Code.app'
==> Unlinking Binary'/usr/local/bin/code'
==> Purging files for version 1.58.2 of Cask visual-studio-codeBefore deleting the application, the system creates a backup copy of the files so that it is easy to roll back if the uninstallation fails. But after successful confirmation of the procedure, the archived copy is deleted automatically.
Uninstalling Homebrew Copy link
If the Homebrew package manager is no longer needed, it can be removed by running a special script. First, download it:
curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.shYou can also review the content:
less uninstall.shTo see the list of supported commands, use the -help flag:
bash uninstall.sh -helpThe command will output the following message:
Homebrew Uninstaller
Usage: uninstall.sh [options] -p, --path=PATH Sets Homebrew prefix. Defaults to /usr/local.
--skip-cache-and-logs
Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.
-f, --force Uninstall without prompting.
-q, --quiet Suppress all output.
-d, --dry-run Simulate uninstall but don't remove anything.
-h, --help Display this message.
Let's run the command with the -d flag, which displays the script's actions:
bash uninstall.sh -dOn the screen, you will see a list of files to be deleted by the script:
Warning: This script would remove:
/Users/brianhogan/Library/Caches/Homebrew/
/Users/brianhogan/Library/Logs/Homebrew/
/usr/local/Caskroom/
/usr/local/Cellar/
/usr/local/bin/brew -> /usr/local/bin/brew
==> Removing Homebrew installation...
Would delete:
...If you're sure about removing Homebrew, run:
bash uninstall.shThe command will uninstall both the Homebrew package manager and the applications that were installed using it.
Conclusions Copy link
We looked at how to install Homebrew on macOS and use the package manager to install other applications and remove unnecessary ones. Using Homebrew makes managing your macOS applications easier not only for developers but also for ordinary users.
By the way, with Hostman, you can run your workloads on an efficient Amsterdam VPS that support low latency for EU-based users. Check this out, we have plenty of budget VPS hosting options for your projects.