System Setup

Installing and configuring the basics.
Author

Michael McCarthy

Published

January 25, 2023

Prerequisites

The following will install, build, and configure the tools used in the remaining posts in this series (and some other things). This is my personal setup for macOS and is intended to get a new computer up and running with the tools and preferences I like to use. A lot of this is general to any data science setup on macOS, but some of it is specific to me.

You are free to use or modify this for your own setup, but should do so thoughtfully. Don’t run any of the scripts below without understanding what they do, and backup your system if you are trying this on an existing setup. To test drive my system setup safely, consider using a virtualized instance of macOS with UTM.

Before you begin

My system setup is done mainly done through the shell prompt in Terminal, which is the easiest recommended way to get a shell prompt on macOS. You can find Terminal in the Utilities directory inside your Applications directory.

If you have never used Terminal before, Apple has a nice shell scripting primer and command line primer book in their archives.

Installing Xcode command line tools

Xcode command line tools are needed to build certain packages from source. The command line tools provide a lighter alternative to installing the full Xcode release from the App Store, which contains a lot that isn’t needed for data science use cases.

Install Xcode command line tools from the Terminal with:

xcode-select --install

Installing Homebrew

Homebrew is an open source package manager for macOS that makes installing, removing, and managing software and dependencies simple.

Install homebrew from the Terminal with:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Installing chezmoi

chezmoi is an open source dotfile manager. Dotfiles are hidden files and hidden directories that store preferences and settings for packages and applications. Dotfiles can be made visible in Finder with the Command-Shift-. keyboard shortcut; learn more about dotfiles here and here.

Install chezmoi from the Terminal with Homebrew:

brew install chezmoi

chezmoi relies on dotfiles being hosted in a public or private Git repository (e.g., GitHub) to share changes across multiple computers. For example, my private dotfiles repository is hosted at: https://github.com/mccarthy-m-g/dotfiles, where I’ve added my dotfiles and other setup scripts. For more information, see:

My setup

With the prerequisites installed, it is now possible to install, build, and configure the remaining tools for my setup. There are many ways to do this, but I use chezmoi’s script support so it’s easy to setup my dotfiles and install software with Homebrew on a new computer using the same command:

chezmoi init --apply $GITHUB_USERNAME

What this does:

  • Clones the dotfiles repository
  • Applies the changes and runs any scripts

Below I cover how to integrate this approach with Homebrew.

Installing software with Homebrew

Homebrew can be used to install almost any software or dependency, whether it’s open source or closed source. Homebrew’s installation commands include:

  • brew: Install software packages (also known as formulae)
  • cask: Install application casks (RStudio, etc.)
  • tap: Add package repositories (from GitHub, etc.)
  • mas: Install Mac App Store applications (requires brew install mas)
  • whalebrew: Install Docker images as if they were Homebrew formulae (requires brew install whalebrew)

Software and dependencies can be installed interactively from the command line, but a better approach for system setup is to use Homebrew Bundle, which allows you to install a list of dependencies located in a Brewfile using any of Homebrew’s installation commands.

The Brewfile to install all the dependencies covered in this series looks something like:

Brewfile
# Version control setup
brew "git"
cask "github"
brew "gh"
tap "microsoft/git"
cask "git-credential-manager-core"

# R setup
tap "r-lib/rig"
cask "rig"
cask "rstudio"
cask "quarto"

# Python setup
brew "pyenv"
brew "openssl"
brew "readline"
brew "sqlite3"
brew "xz"
brew "zlib"
brew "tcl-tk"
brew "pipenv"

# Reference manager setup
cask "zotero"

After making a Brewfile, install its dependency list with:

brew bundle

Use the optional --file argument to specify the path to the Brewfile.

Create a Brewfile of your current Homebrew installations in the current working directory with:

brew bundle dump

Uninstall all software and dependencies not listed in a Brewfile with:

brew bundle cleanup

To integrate Homebrew Bundle with chezmoi, create a run_once_ script containing the Brewfile as a Here document in your dotfiles repository:

run_once_before_install-packages-darwin.sh.tmpl
{{- if eq .chezmoi.os "darwin" -}}
#!/bin/bash

brew bundle --no-lock --file=/dev/stdin << Brewfile
# Version control setup
brew "git"
cask "github"
brew "gh"

# R setup
tap "r-lib/rig"
cask "rig"
cask "rstudio"
cask "quarto"

# Python setup
brew "pyenv"
brew "openssl"
brew "readline"
brew "sqlite3"
brew "xz"
brew "zlib"
brew "tcl-tk"
brew "pipenv"

# Reference manager setup
cask "zotero"
Brewfile
{{ end -}}

This script will be run the first time you initialize chezmoi (as shown earlier):

chezmoi init --apply $GITHUB_USERNAME