Brew Command Not Found Macos Catalina

Tutorial

Introduction

The command line interface is a non-graphical way to interact with your computer. Instead of clicking buttons with your mouse, you’ll type commands as text and receive text-based feedback. The command line, also known as a shell, lets you automate many tasks you do on your computer daily, and is an essential tool for software developers.

Homebrew is a package managing tool. It’s more popular on Linux but is also used extensively on macOS. In fact, for apps that install as packages, Homebrew is the easiest way to remove them. Here’s how you can install Homebrew on macOS Catalina. In order to install Homebrew on macOS Catalina, you must have Xcode installed. For bundler I did the following on Catalina $ brew install v8@3.15 $ bundle config build.libv8 -with-system-v8 $ bundle config build.therubyracer -with-v8-dir=$(brew -prefix v8@3.15) $ bundle install Worked on Big Sur, tks!

MacOS 10.15 Catalina Mostly-Automated Setup. An easy to refer to document for regularly setting up macOS 10.15 Catalina. The topic of recipe-based frequent fresh reinstalls of macOS is a controversial issue. Some people are against reinstalling macOS, citing that they have never had an issue with Apple provided upgrade installs. The modern mac os recovery environment automatically logs in as root. So the su or sudo command is not necessary since you are already using superuser privilages. Try the command ls -lah to see your permessions of the current directory. Or ls -lah whoami to see your user permissions.

While the command line interface on macOS has a lot of the functionality you’d find in Linux and other Unix systems, it does not ship with a package manager. A package manager is a collection of software tools that work to automate software installations, configurations, and upgrades. Package managers keep the software they install in a central location and can maintain all software packages on the system in formats that are commonly used.

Homebrew is a package manager for macOS which lets you install free and open-source software using your terminal. You’ll use Homebrew to install developer tools like Python, Ruby, Node.js, and more.

In this tutorial you’ll install and use Homebrew on your Mac. You’ll install system tools and desktop applications from the command line interface.

Prerequisites

You will need a macOS computer running Catalina or higher with administrative access and an internet connection. While older versions of macOS may work, they are not officially supported.

Step 1 — Using the macOS Terminal

To access the command line interface on your Mac, you’ll use the Terminal application provided by macOS. 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.

To get more comfortable using the command line, take a look at An Introduction to the Linux Terminal. The command line interface on macOS is very similar, and the concepts in that tutorial are directly applicable.

Now that you have the Terminal running, let’s install some additional tools that Homebrew needs.

Step 2 — Installing Xcode’s Command Line Tools

Xcode is an integrated development environment (IDE) that is comprised of software development tools for macOS. You won’t need Xcode to use Homebrew, but some of the software and components you’ll want to install will rely on Xcode’s Command Line Tools package.

Execute the following command in the Terminal to download and install these components:

You’ll be prompted to start the installation, and then prompted again to accept a software license. Then the tools will download and install automatically.

You can now install Homebrew.

Step 3 — Installing and Setting Up Homebrew

To install Homebrew, you’ll download an installation script and then execute the script.

First, download the script to your local machine by typing the following command in your Terminal window:

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 flag tells the Terminal window to give no HTML document output on server errors.
  • The -s or --silent flag mutes curl so that it does not show the progress meter, and combined with the -S or --show-error flag it will ensure that curl shows an error message if it fails.
  • The -L or --location flag will tell curl 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 download from the Internet, you should review its contents so you know what the script will do. Use the less command to review the installation script so you understand what it will do'

Once you’re comfortable with the contents of the script, execute the script with the bash command:

The installation script will explain what it will do and will prompt you to confirm that you want to do it. This lets you know exactly what Homebrew is going to do to your system before you let it proceed. It also ensures you have the prerequisites in place before it continues.

You’ll be prompted to enter your password during the process. However, when you type your password, your keystrokes will not display in the Terminal window. This is a security measure and is something you’ll see often when prompted for passwords on the command line. Even though you don’t see them, your keystrokes are being recorded by the system, so press the RETURN key once you’ve entered your password.

Press the letter y for “yes” whenever you are prompted to confirm the installation.

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 tools that macOS includes.

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 used as the default, and if you’ve upgraded your OS, you may still be using Bash.

Execute the following command to determine your shell:

You’ll see either bash or zsh.

If you’re using ZSH, you’ll open the file ~/.zshrc in your editor:

If you’re using the Bash shell, you’ll use the file ~/.bash_profile:

Once the file opens up in the Terminal window, add the following lines to the end of the file:

The first line is a comment that will help you remember what this does if you open this file in the future.

To save your changes, hold down the CTRL key and the letter O, and when prompted, press the RETURN key. Then exit the editor by holding the CTRL key and pressing X. This will return you to your Terminal prompt.

To activate these changes, close and reopen your Terminal app. Alternatively, use the source command to load the file you modified.

If you modified .zshrc, execute this command:

If you modified .bash_profile, execute this command:

Once you have done this, the changes you have made 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. Execute this command:

If no updates are required at this time, you’ll see this in your Terminal:

Otherwise, you may get a warning to run another command such as brew update to ensure that your installation of Homebrew is up to date. Follow any on-screen instructions to fix your environment before moving on.

Step 4 — Installing, Upgrading, and Removing Packages

Now that Homebrew is installed, use it to download a package. The tree command lets you see a graphical directory tree and is available via Homebrew.

Install tree with the brew install command:

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:

The output shows that tree is located in /usr/local/bin:

Run the tree command to see the version:

The version prints to the screen, indicating it’s installed:

Occasionally, you’ll want to upgrade an existing package. Use the brew upgrade command, followed by the package name:

You can run brew upgrade with no additional arguments to upgrade all programs and packages Homebrew manages.

When you install a new version, Homebrew keeps the older version around. After a while, you might want to reclaim disk space by removing these older copies. Run brew cleanup to remove all old versions of your Homebrew-managed software.

Brew Command Not Found Macos Catalina Version

To remove a package you’re no longer using, use brew uninstall. To uninstall the tree command, execute this command:

The output shows that the package was removed:

You can use Homebrew to install desktop applications too.

Step 5 — Installing Desktop Applications

You’re not restricted to using Homebrew for command-line tools. Homebrew Cask lets you install desktop applications. This feature is included with Homebrew, so there’s nothing additional to install.

Test it out by using Homebrew to install Visual Studio Code. Execute the following command in your terminal:

The application will install:

You’ll find the application in your Applications folder, just as if you’d installed it manually.

To remove it, use brew uninstall:

Homebrew will remove the installed software:

It performs a backup first in case the removal fails, but once the program is fully uninstalled, the backup is removed as well.

Step 6 — Uninstalling Homebrew

If you no longer need Homebrew, you can use its uninstall script.

Download the uninstall script with curl:

As always, review the contents of the script with the less command to verify the script’s contents:

Once you’ve verified the script, execute the script with the --help flag to see the various options you can use:

The options display on the screen:

Use the -d flag to see what the script will do:

The script will list everything it will delete:

When you’re ready to remove everything, execute the script without any flags:

This removes Homebrew and any programs you’ve installed with it.

Conclusion

In this tutorial you installed and used Homebrew on your Mac. You can now use Homebrew to install command line tools, programming languages, and other utilities you’ll need for software development.

Homebrew has many packages you can install. Visit the official list to search for your favorite programs.

This guide is intended to be a complete guide to setting up R (free desktop version) on a clean macOS Catalina installation. It shows how to get R, the R App and R Studio to all use the same R packages, as well as how to ensure installation of pre-built binary packages from CRAN when possible, or to otherwise build from C/C++, and Fortran source with OpenMP support.

Motivation

If you’re not careful how you install R on macOS, when you try to install R packages, R may try to build those packages from source. We like our package managers. They usually make finding and installing software a cinch. On macOS, the two most popular ones are MacPorts and Homebrew (a.k.a. brew). In this post, I’ll be using brew – partially. If you’re already a brew fan and have had to install R, you most like did so with brew install r. This is probably the wrong choice for most people as this could prevent R from using pre-built binaries when installing packages.

Installing R packages from source can take a long time and there’s usually no advantage to doing so. Even if you force the R package installer to install the binary package instead of building it from source, these binary packages may expect R itself to be installed in a specific location and won’t work if they can’t find and link to the R framework.

Moreover, unless you know what you’re doing, you’ll likely not build the package correctly for optimal speed and performance. If you’re building from source and require optimal performance, you’ll have to spend some time profiling your builds to ensure they are getting built optimally.

Background

R is built from C, Fortran and recursively from R source code itself. CRAN (Comprehensive R Archive Network) is the main repository for R packages from which you will install most of the packages you need. Packages hosted on CRAN include pre-built binary packages targeted for Windows and macOS. If you use a version of R that was built by CRAN, it will be able to download and install the pre-built binaries “out of the box” without having to build them from source.

You may still need to build from source from time to time, so I’ll also cover how to set up LLVM and GNU Fortran with OpenMP support. Even though the macOS Command Line Tools from Apple includes an LLVM compiler, there is still no support for OpenMP, so we’ll need to install our own version (via brew).

Installing R

  1. Visit cran.r-project.org
  2. From the menu on the left panel, select Mirrors
  3. Select the site closest to you
  4. In the main section, select Download R for (Mac) OS X
  5. Find the latest package. It will be named something similar to R-3.6.0.pkg according to the latest version available.

This package contains the following:

  • R Framework
  • R GUI
  • Tcl/Tk
  • Texinfo

You absolutely need R Framework. This will be installed in /Library/Frameworks where pre-built binaries will look for it, if needed. This is why you need to install this version of R in order to make use of pre-built packages.

R GUI is a terminal-like environment created specifically for R. If you will be using R Studio (highly recommended), you won’t use R GUI very much. If you want to access R from a terminal session instead of the R GUI, stay tuned; this will be covered too.

Kick off the installation process by opening the package you just downloaded. When you get to the Installation Type make sure you select Customize.

2020-05-02 UPDATE: If you need Tck/Tk and/or Texinfo support, it seems that you must install those options with this R installation software. As far as I can tell, the paths to these libraries are configured during the building of the software package and there doesn’t seem to be a feasible way to change these paths without rebuilding the software. If I find out otherwise, I’ll revise this update. If you don’t know what these libraries are for, you probably don’t need them in which case, feel free to not install them.

IMPORTANT:You should NOT install Tcl/Tk and Texinfo if you plan on using brew as your package manager. These packages are installed to /usr/local and brew doctor (the diagnostics options that checks the validity of your brew installation) will complain about this. We will install these two packages via brew instead.

R 3.6.0 binary for OS X 10.11 (El Capitan) and higher, signed package. Contains R 3.6.0 framework, R.app GUI 1.70 in 64-bit for Intel Macs, Tcl/Tk 8.6.6 X11 libraries and Texinfo 5.2. The latter two components are optional and can be ommitted when choosing “custom install”, they are only needed if you want to use the tcltk R package or build package documentation from sources.

Set some defaults

Before you start installing packages, you should think about where you will be saving all these packages as well as which CRAN mirror site you’ll be downloading from.

  • Default Library Paths - By default, packages you install will be saved to /Library/Frameworks/R/... and down a few more subfolders that you’ll never remember! Also, if you ever have to do a clean reinstall of the R Framework, you’ll have to reinstall all your packages too. I recommend you change this default.

  • You should determine which CRAN mirror site is physically closest to you. This will improve your download times. If you don’t set a default site, R will ask you to select one every time you want to install a package. Alternatively, you can select 0-Cloud [https] which redirects you automatically to an appropriate site. Select [https] over [http] when you have a choice.

0-Cloud

https://cloud.r-project.org/

Automatic redirection to servers worldwide, currently sponsored by Rstudio

R App

Terminal

If accessing R from the terminal, the setup for these two options can be done in ~/.Rprofile. If this file doesn’t exist, create it and add the following lines:

NB:

  1. I’ve set the CRAN mirror to be selected automatically but you can change the URL to a specific mirror if you wish
  2. For the library path, replace <username> with your account username and <r-version> with the version of R you installed (I installed 3.6)
  3. You can use any path you want for the default library path but since the R App forces you to use this one, you might want to stick with it if you’re using R via both the R app and the terminal.
  4. Upon restarting the R app, this directory will be created if it doesn’t exist
  5. On some R installations, if you want to preserve the system library path, you’ll need to re-include it using .libPaths(). For example:

If you are not using the R app, you will need to make sure that the path you specify exists. For example,

R from your zsh shell

If you are using the zsh shell, r may already be reserved for re-running your last command. Since you can also do this with !! or by scrolling back through your history with the up-arrow key, you can disable this functionality and use it to launch R. In your ~/.zshrc file:

Brew Command Not Found Macos Catalina Os

Now you can use both r and R to invoke R.

Homebrew & Xcode Command Line Tools

From this point, you should be able to use brew to install almost everything else. You can find installation instructions on the official site.

Installing Homebrew will also install the Xcode Command Line Tools if not already installed. If you already have Homebrew installed and are not sure if the Xcode Command Line Tools are installed, you can try to install them now. If already installed, you’ll simply get an error message telling you they are already installed.

Tcl-tk and Texinfo

2020-05-02 UPDATE: Installed this way, the tcl-tk package is not automatically found by R. If you want Tcl/Tk support, you should include it with the base R installation software. You’ll just have to live with the brew doctor warnings.

These are the two packages we ommitted during the R installation so that they didn’t conflict with Homebrew. We now install them via brew.

SDK Header Files, LLVM & GCC

There are times when you’ll want to or need to build from source. For instance, if you’re installing from a repository whose package only has source code, or if the source code is more recent than the binary version, R (by default) will build from source.

SDK Header Files

2020-05-01 UPDATE: I no longer recommend exporting paths to the SDK header files for the purpose of building R packages, as I’ve experienced some side effects in the past and had to remove them from my own setup. The path to the SDK is now also configured in Makevars (see further down in this article).

Even though both Xcode and the Command Line Tools are installed, some build systems still have trouble locating the macOS SDK header files. They expect system header files to be located in /usr/include. However, both Xcode and the Command Line Tools install them elsewhere. Apple used to provide a separate installation package (as part of the Xcode installation) that would install these SDK header files in /usr/include. However, Apple no longer provides this package.

Instead, you can set the correct path to the SDK header files by including something like this in your ~/.bash_profile (if you use bash) or ~/.zshrc file (if you use zsh). Note that Catalina’s default shell is now Zsh.

This will not take effect in your current terminal session. However, you should be able to restart your session with source $SHELL or by specifying the precise path to your shell’s binary executable (e.g.: source /bin/zsh).

Zsh Command Not Found Brew Macos Catalina

Command

LLVM

The Apple-supplied version of the LLVM compiler (clang) doesn’t include support for OpenMP. Install the latest from brew:

Test OpenMP

Now test your installation against OpenMP. Your shell’s environment should be configured to find the macOS SDK header files. Create a file called omptest.c:

Then try to build and run it:

GCC

The GNU compiler collection includes gfortran which is sometimes needed. Install gcc without multilib (cross platform) support so that openmp support is possible.

You no longer need to include --without-multilib on 64-bit-only systems as it is automatically disabled but it doesn’t hurt to add it.

How To Install Brew On Macos Catalina

Configure R to use LLVM & GCC

To configure R to build packages with the versions of clang and gcc you just installed, set up a Makevars file. This must be located at ~/.R/Makevars. I’ve crafted this file from Internet research and some trial & error and have included some reference links in case you’re interested.

C/C++

Now, try building from R. A good test is the data.table package. Uninstall it first, if it’s already installed.

Then, install it from source:

If R installs it without error, you are set up to build C/C++ source code with OpenMP support. However, you should reinstall this package from the CRAN binaries unless you have a good reason against, so that you get optimal performance.

Fortran

You can also test to make sure your configuration can build Fortran code against the OpenMP libraries by installing an appropriate R package, e.g.: bayesQR.

If all goes well, your setup is properly configured to build from Fortran source code with OpenMP support.

How To Install Homebrew On Macos Catalina

Install R Studio

R Studio is available as a Homebrew cask. However, it requires the R cask to be installed. We avoided installing R this way because it doesn’t allow a custom installation and can’t install pre-build binary packages from CRAN. I therefore recommend installing R Studio by downloading the installer from rstudio.com.

Brew Command Not Found Macos Catalina Update

XQuartz & X11

It is possible to get X11-related warnings or erros when installing packages or loading other R libraries.

Brew Command Not Found Macos Catalina Download

If at any point you need to install X11:

Time Machine

I find it unnecessary to back up installed packages to Time Machine, both from brew and R. In the event of a system restore, these packages are very easy to re-install. You can add the following exclusions to Time Machine, either via the Time Machine GUI settings or from the command line: