How I Set Up A New Laptop

Well it’s that time again, migrating for one reason or another listlessly between computers as priorities and jobs change. Here’s a middle-depth breakdown of how I speed-run getting a new machine off the ground. This post is for Mac computer users who might be interested in automating their setup workflow.

TL;DR

It’s like 85% Homebrew automation and about 5% dotfiles and about 3% curling tools that aren’t on Homebrew and 1% making sure Mac settings are correct. What you do with that remaining 6% is up to you, I’ve granted it to you as a gift — do not forget this kindness.

Preheat the oven with Homebrew

Right off the bat I’ll kick open a Terminal window and install Homebrew, which is a package manager for OSX. This tool will handle almost all of my installs going forward — I’m personally quite allergic to the dance of downloading, installing, and subsequently deleting ten thousand .pkg files from all corners of the 'Net, and besides, this is ✨ automated ✨.

The install steps that Homebrew asks for change over time, so your best bet is to visit the Homebrew website and follow their directions, but at the time of writing, the standard way of installing is a shell command:

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

It’s generally poor form to go pasting things from random places on the internet into your Terminal. You can trust me though, I’m like a chill internet stranger.

Dotfiles Mise en Place

You’ve probably encountered dotfiles before, the janky extensionless files at your home directory that you sometimes have to edit to get certain shell commands to work, etc. Because they have so much potential for configuration, it’s super useful to store them online and reuse them, and that’ll power much of our setup. Plenty of folks have written at length about this pattern, so I won’t dive too deep here. Basically, we’re gonna create a GitHub repo at our home directory, .gitignore everything (because we don’t want to just be adding everything all wilson-nilson), and force-add only the relevant files. That repo will then be a quickly-downloaded source of truth for our hard-fought finicky IDE/terminal/prompt config.

I’ve currently got three configuration files in my dotfiles repo: a .hyper.js JSON config for Hyper terminal, a .zshrc for making my zsh + oh-my-zsh + spaceship setup work well, and a Brewfile.

Setting Up Git And Dotfiles

If I’ve got my dotfiles ready on an old laptop, I’ll need to clone them onto a new machine. The first step for that is making I can even access the repo to clone it. I use GitHub to store my git projects, so I can follow their directions for:

(Obviously you could just copy and paste from the browser but I use GitHub daily anyhow, may as well do this step now and never worry about it again!)

Once that’s sorted, I can put dotfiles where they belong. Since the home directory already has stuff in it, it won’t be possible to just git clone, so what we can do instead is:

cd ~
git init
git remote add origin DOTFILES_REPO_URL 
git reset origin/main # we have to do this in case any of the files in dotfiles already exist
git checkout origin main

Now our Brewfiles/.zshrc/etc should have made it to where they belong! Next we can install all the apps that will adopt these configurations.

Installing apps with Brewfiles

One of the cooler features of Homebrew is its ability to consume package files called Brewfiles (similar to Gemfiles, if you’re into the Ruby ecosystem at all), which can perform any number of sequenced actions. I’ve got most of my day-to-day apps and CLI tools sorted in the Brewfile I just pulled in the last step, and I can install them all at once. I’ve included a snippet of that Brewfile here, and you can view the whole thing over here.

# Mac Apps with `--cask`
cask "alfred"
cask "firefox"

# CLI tools with `brew install`
brew "node"

# Even font files are fair game
tap "homebrew/cask-fonts" # point Homebrew to where the font file lives
cask "font-inconsolata-nerd-font" # install it

Once I’ve got my shopping list of apps set up, I can install all of them at once with a quick Homebrew command:

brew bundle install

Homebrew automatically looks to install from ~/Brewfile if no other location is specified, so that Dotfiles import works seamlessly. Homebrew also has really straightforward logging — it’ll clearly indicate what it’s doing, and which of its actions were successful or not.

Installing apps without Brewfiles

I use two tools that don’t jive well with Homebrew installation: nvm and oh-my-zsh.

NVM is a version manager for Node, and they explicitly say on the repo install guide that Homebrew install isn’t supported. Theirs is—at the time of writing—just a curl command to run their install script:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Remember what I said about running random commands you find online? Doesn’t it seem like Apple should’ve made a secure, native package manager so installing stuff doesn’t feel so back alley?

Oh My Zsh is a config manager for zsh — it enables plugins like the extremely useful git shortcuts and aliases plugin. It’s also a curl command:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

And that ought to do it for installs for my default setup.

Last Steps

Believe it or not, that should be everything sorted. Homebrew does so much of the heavy lifting, usually all that remains is to do some logins (easily done if one uses a password manager 👀) and configure final Mac settings! I personally set auto-keyboard intervention to off as a default (I can’t with the auto-capitalization and spellcheck), as well as turn on the battery percentage in the top bar.

Thanks for reading! Hope it was useful, and I hope you find some meaningful, fitting way to get revenge on me for the time wasted if not. If you’re following this like it’s a tutorial and run into any issues, please definitely let me know!

More Writing

  • How To Map A Number Between Two Ranges

    Tutorial

    • math
    • javascript
    Read the post
  • A One-Liner For Freeing Ports on OS X

    Resource

    • bash
    Read the post
  • Using Focal Points, Aspect Ratio & Object-Fit To Crop Images Correctly

    Tutorial

    • css
    • css variables
    • aspect-ratio
    • object-fit
    Read the post