3 Package Managers
Note: This is a fast-track guide designed to get macOS users up and running with tools like Visual Studio Code (VS Code) and SageMath quickly. A more thorough discussion of package managers, including support for Linux and Windows subsystems, will be developed in the future.
Motivation and scope
Coming soon
When we want to install new software on a Mac, the most common approach is to visit the developer’s official website, download a .dmg file, double-click to mount it as a virtual disk, and drag an .app bundle into our Applications folder.1 This graphical approach is familiar and generally harmless: at a basic level, we are simply copying the program’s files into a standard system location so macOS can run them. However, beyond the application itself, any additional dependencies or updates typically need to be managed manually.
As we move toward building reproducible, professional environments for mathematical computation, this manual approach breaks down. When we install programming languages or specialized mathematical software, these tools often rely on dependencies—i.e., other pieces of software they need in order to function. If we install these manually, our system can become a complex, precarious, and difficult environment to manage: updating or cleanly uninstalling software becomes nearly impossible, hidden files end up scattered across our system directories, and conflicts can make replicating setups on different systems unnecessarily challenging.
To solve this, we use a package manager. This is a command-line tool that automates the process of installing, updating, configuring, and removing programs. Managers maintain a centralized registry of what is installed on our machine and automatically resolve the associated dependency graph. Homebrew has become the de facto standard package manager on Mac—despite not being officially bundled with Apple software, this open-source system has become the most popular package manager for macOS.
Core concepts
Coming soon
Getting started
Terminal
The brief explanation given here will soon be moved to (and more throughly described in) Chapter 2.
Because package managers operate via a command-line interface (CLI), we first need to open a terminal emulator. For now, we can think of the terminal as a direct, text-based way to control our system, bypassing the visual metaphors of folders and icons. To open it on macOS, we can use Spotlight Search (press Cmd-SpaceCmd-Space), start typing “terminal”, and press once it appears in the results. We should see a window open with a cursor waiting for input, indicating that the system is ready to receive instructions.
Setup
To install Homebrew, we need to visit their official website, brew.sh, and copy the installation command provided on the homepage. It will look something like this:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Let’s break down what this command is actually doing before we press Enter:
curlis a program that downloads data from a URL.-fsSLis a list of flags which modify the use ofcurlhttps://.../install.shis the address of a script (a list of instructions) written by the Homebrew team./bin/bash -ctells our computer to execute that script immediately.
Be cautious about copying and pasting commands from the internet into the terminal, especially those involving curl or sudo. A malicious script can silently compromise our machine, or much worse! We only run this command because Homebrew is a popular, open-source project whose installation scripts are constantly scrutinized by thousands of developers.
When we paste this command into our terminal and press Enter, several instructions will follow. Among these are:
- The Password Prompt: The terminal will ask for our Mac login password. This happens because the installation script invokes
sudo(short for “superuser do”), a command that grants the script temporary administrative privileges needed to write files to protected system locations. Be careful with notifications like this!—We are handing the keys to the entire operating system over to the script. For Homebrew, this is a necessary and well-vetted step. If you ever feel unsure about the permissions requested by a command, ask for help!
As we type our password, no characters will appear on the screen! This is a standard Unix security feature—simply type the password and press Enter.
- Xcode Command Line Tools: Homebrew requires certain foundational tools built by Apple to compile software. If our machine doesn’t have them yet, the script will pause to download and install the Xcode Command Line Tools. This will take some time!
The PATH
When the installation completes, the script will print a few lines under the heading ==> Next steps:.
The terminal relies on an environment variable called the PATH—a literal list of directories the computer searches through whenever we type a command. If we type python, the computer checks its PATH to find the folder where the Python program actually lives.
Because Homebrew installs itself into a special, isolated folder (/opt/homebrew on modern Macs), our terminal doesn’t inherently know it exists. We have to add Homebrew to our PATH. The installer provides the commands we need to run to fix this. They generally look something like this:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/username/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"Copy and paste the specific lines provided by your terminal (not the block above, which doesn’t have your username populated!) and press Enter.
On an older Macs (2019 and earlier) with Intel processors, Homebrew installs itself into /usr/local/ instead of /opt/homebrew/. The installer will give you the correct command!
To verify the installation was successful, we can ask Homebrew for its version details:
brew --versionIf this command returns a version number (e.g., Homebrew 5.1.6), we are ready to proceed!
Basic Usage
Installing Programs
Homebrew divides software into two broad categories:
- Formulae: Command-line interface tools, libraries, and background services (like
Git,graphviz, ormactop). - Casks: Graphical applications (like Google Chrome, VS Code, Spotify, or Bitwarden).
For instance, a fantastic tool for visualizing the “directed tree” of our file system is tree. We can install it via:
brew install treeOnce installed, typing tree into our terminal will print a visual map of all the files and folders inside your current directory.
On the other hand, we use the --cask flag to install a graphical application. For example, to install Google Chrome, we would run:
brew install --cask google-chromeIf we want to install an application but aren’t sure of its exact registry name, we can search for it:
brew search google chromeMaintenance
The true power of a package manager becomes clear when we need to update our software or clean up our machine. To update the centralized registry of available software, we tell Homebrew to fetch the latest lists:
brew updateThen, instead of opening each of our applications to check for updates, we can update everything installed via Homebrew by executing:
brew upgradeMoreover, if we are ready to move to a web browser that is a little less curious about everything we do online, we don’t have to hunt down hidden preference files in our system library! We simply run:
brew uninstall --cask google-chromeFrom here, Homebrew will completely and cleanly remove the application and any associated data that it installed. We can also remove outdated versions of software and old installation files from the cache to save disk space:
brew cleanup Replication
Package managers make setting up a new machine trivial. In the future, we will explore tools like a Brewfile—a simple plaintext list of all the software we rely on. When we move to a new computer, we can simply hand that file to Homebrew and leave it to perfectly recreate our entire computational environment.
Tools and Neat Packages
Now that we have Homebrew set up, we can quickly customize the system to our needs. We briefly mention some useful tools for scientific computing and general productivity, some of which will be discussed later in the book.
Productivity
These are graphical apps that live in our Applications folder.
rectangle: Software which replaces the basic window tiling available since MacOS Seqouia, allowing us to snap windows across the screen using mouse and keyboard shortcuts.brew install --cask rectangleWhile we’re at it, we can turn off the margins between tiled windows via
Settings >> Desktop & Dock >> Windows.visual-studio-code: A free, open-source, and mature code editor which enjoys a strong community and ecosystem of extensions.brew install --cask visual-studio-codeSome alternatives are
vscodium(VS Code with Microsoft’s telemetry disabled) andzed(a fashionably minimalist, GPU-accelerated, and LLM-ready editor), though we focus on VS Code in Section Chapter 5.obsidian: A knowledge-base and notetaking system that operates on Markdown files (Chapter 8).brew install --cask obsidian
System Utilities
These are command-line tools which serve very specific purposes.
git: An open-source and widely adopted version control system designed to track changes in code during software development, to be discussed in Chapter 4.brew install gitmactop: A much more readable, colorful, and customizable version of the system’s “Activity Monitor,” which is especially useful when we want to understand how calculations are taxing our system’s CPU, GPU, and memory.brew install mactoptree: (As mentioned above) A tool for visualizing and communicating the structure of our projects.ffsend: An open-source tool designed for secure file sharing using the Firefox Send protocol, allowing the creation of end-to-end encrypted links which are time- and download-limited.brew install ffsend
Best practices
Coming soon
After installation, don’t forget to “eject” the mounted volume from your desktop or Finder—just like a physical disk—and then delete the
.dmgfile!↩︎