Skip to content

[Blog] Setting up a new computer/laptop (macOS) #79

Open
@0xdevalias

Description

@0xdevalias

It would be cool to write about how I set up a new laptop, encoding some of my currently more manual processes, and the order that makes most sense in doing so.

Setting up a new laptop

Pre-Bootstrap

Go through the macOS installer, configure any settings as desired.

Once you've booted into macOS for the first time, it probably makes sense to check for any system updates (particularly major OS updates) and install those before continuing.

  • Open System Preferences, click Software Update, check for/install any updates

(Optional) At this stage, it may also be useful to get a snapshot of the default configurations on a freshly installed version of macOS. This can be useful for updating the scripts that configure macOS defaults (see 'dotfiles' section below)

  • Open Terminal and run defaults read > ~/Desktop/macOS-defaults.txt

Bootstrap

(Optional) Install command line development tools.

This will generally be performed as part of the Homebrew install script (see below), but if you want to do it manually, you can do this now (it's required for the default system installations of tools such as git, etc)

  • Open Terminal and then run xcode-select --install

If you try to run a command line tool such as git before installing this, you will see a message similar to the following:

xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.

image

Install Homebrew

Homebrew is a package manager that makes it easy to install all of the other applications we want on our machine.

It can be easily installed by opening Terminal and running the following command:

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

Once this is done, you probably also want enable the homebrew 'cask' 'tap', to be able to instal non CLI applications as well:

brew tap homebrew/cask

Dotfiles, defaults and core applications

Once I have my basic bootstrap tools installed, I can clone my dotfiles repo, and run some more automated setup scripts to get my environment exactly how I like it.

Open Terminal and clone my dotfiles repo. Note that we use https (rather than ssh) to clone for now, as we don't have ssh keys setup on our new machine yet:

git clone https://github.com/0xdevalias/dotfiles.git ~/.dotfiles

Make any customisations you may need before running. At a minimum, I would suggest checking that the latest versions are setup in:

  • TODO: ruby, python, node, etc?

Note: I hit a number of issues when running this that we should figure how to fix:

› /Users/devalias/.dotfiles/homebrew/install.sh
Already up-to-date.
› /Users/devalias/.dotfiles/antigen/install.sh
  › antigen update
Loading antigen..
  [ERROR] Antigen loader requires homebrew to be installed. Exiting.
› /Users/devalias/.dotfiles/zsh/install.sh
/Users/devalias/.dotfiles/zsh/install.sh: line 15: default-user-shell: command not found
/Users/devalias/.dotfiles/zsh/install.sh: line 16: default-user-shell: command not found
Setting default shell to zsh (homebrew) from ''
Changing shell for devalias.

After running the bootstrap, and restarting my terminal, it also seems as though it won't run all of the 'init scripts' correctly, due to missing programs, etc; which eventually cause the shell to exit with an error. These should either be included as part of a 'core required tools' step, or be smart enough to exit cleanly without running if those tools aren't already present:

Loading antigen..
  [ERROR] Antigen loader requires homebrew to be installed. Exiting.
/Users/devalias/.dotfiles/go/path.zsh:1: command not found: go
/Users/devalias/.dotfiles/ruby/path.zsh:9: command not found: rbenv
Loading gpg-agent..
[ERROR] Couldn't find 'gpg'. Try:
  brew install gpg

[brew-info]
  gnupg: stable 2.2.20 (bottled)
  GNU Pretty Good Privacy (PGP) package
  https://gnupg.org/
  Not installed
  From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gnupg.rb
  ==> Dependencies
  Build: pkg-config
  Required: adns, gettext, gnutls, libassuan, libgcrypt, libgpg-error, libksba, libusb, npth, pinentry
  ==> Analytics
  install: 36,942 (30 days), 123,847 (90 days), 522,421 (365 days)
  install-on-request: 31,731 (30 days), 105,365 (90 days), 435,775 (365 days)
  build-error: 0 (30 days)
[ERROR] Couldn't find 'pinentry-mac'. Try:
  brew install pinentry-mac

[brew-info]
  pinentry-mac: stable 0.9.4 (bottled), HEAD
  Pinentry for GPG on Mac
  https://github.com/GPGTools/pinentry-mac
  Not installed
  From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/pinentry-mac.rb
  ==> Requirements
  Build: xcode
  ==> Options
  --HEAD
    Install HEAD version
  ==> Caveats
  You can now set this as your pinentry program like
  
  ~/.gnupg/gpg-agent.conf
      pinentry-program /usr/local/bin/pinentry-mac
  ==> Analytics
  install: 2,450 (30 days), 7,469 (90 days), 29,599 (365 days)
  install-on-request: 2,352 (30 days), 7,257 (90 days), 28,411 (365 days)
  build-error: 0 (30 days)
/Users/devalias/.dotfiles/gpg/gpg_agent.zsh:20: command not found: gpg2

  [ERROR] failed to parse gpg-config, not starting gpg-agent

[Process completed]
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?

If you see this, you can say n for the time being, then once your shell starts, run the following command to ensure the directories aren't world writeable:


Once everything is updated as desired, run script/bootstrap to install things:

cd ~/.dotfiles
script/bootstrap

At time of writing, this will:

  • configure name/email/etc for .gitconfig
  • link any *.symlink files from the dotfiles repo into $HOME
  • run bin/dot
    • sets up macOS defaults
    • ensures homebrew / mas are installed
      • TODO: add whalebrew and similar package management type things here too?
    • ensures antigen is installed
    • ensures zsh is installed
    • offers to run install scripts for various topics
    • offers to check for macOS updates

Note that the automatic running of installs scripts is a little manual/haphazard at the moment, mostly because I don't necessarily want to automatically install everything on a new machine. I would suggest checking the code to see what will be run, and sanity checking that each is going to do what you want it to. A lot of these scripts end up being run once per new machine, so they can drift/become outdated from my 'ideal setup' over time.

Eventually I would like to clean this up and standardise it a bit more, to be a 'bare minimal' set (eg. core development environments for node, python, ruby, etc. Though I think when that happens, it may make sense to do so as part of adopting a dotfiles management tool (see 0xdevalias/dotfiles#8)

For now, refer to the below sections for a more 'manual' list of core installs/setup tasks for a new dev machine. I've roughly attempted to document them in the order I would follow, but this isn't necessarily a hard requirement.

Computer Name

Basic text/code editor

  • Basic text/code editor: ~/.dotfiles/sublimetext/install.sh
    • TODO: move this into the above 'core' list of things?

Generate SSH key for GitHub, GitLab, Bitbucket, etc

  • Generate SSH key for GitHub, GitLab, Bitbucket, etc:
    • TODO: automate this as part of script/bootstrap
    • https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
    • ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/github_YOURUSERNAME_ed25519
      • Set a password on this key for extra security
    • Once you've created it, you need to add the public key to your GitHub account
    • TODO: add ssh config entry for GitHub
    • Now we want to add the key to ~/.dotfiles/ssh/keys.init so that ssh-keyinit works correctly
      • This file is just a list of the keys to be loaded with ssh-add
      • eg. github_USERNAME_ed25519 bitbucket_USERNAME_rsa gitlab_USERNAME_rsa
      • Once this is done, we can run ssh-keyinit once after restarting our machine, and it will load the specified keys for us
    • Once you have this SSH key setup, we can change our cloned dotfiles git repo to use SSH instead of HTTPS for it's remote

Terminal/Shell (iTerm2)

GPG (git commit signing, etc)

  • GPG (gpg, pinentry-mac):
    • ~/.dotfiles/gpg/install.sh
    • TODO: move this into the above 'core' list of things?

Keybase

  • Keybase: brew cask install keybase
    • Login to Keybase and verify it with one of your previously linked devices
    • TODO: anything needed to setup CLI tools, file system, gpg keys, etc?
      • keybase pgp list
      • keybase pgp pull-private THEGPGKEYID (repeat for other keys as required)
        • Once this is done, you may want to update your signingkey in ~/.dotfiles/git/gitconfig.local.symlink
          • gpg --list-secret-keys --keyid-format LONG
          • git config --file ~/.gitconfig.local --set user.signingkey THE16CHARKEYID
          • TODO: this should be automated as part of git config setup in script/bootstrap or similar
  • Note: Some of this is closely related to/relies on GPG being setup first

Development Tools (Java, Node, Python, Ruby, Golang, Swift, Xcode, etc)

  • Dev environment managers:
    • Java (jenv, etc): ~/.dotfiles/java/install.sh
    • Node (nodenv, etc): ~/.dotfiles/node/install.sh
    • Python (pyenv): ~/.dotfiles/python/install.sh
    • Ruby (rbenv): ~/.dotfiles/ruby/install.sh
    • TODO: Golang (goenv)?
    • TODO: Swift (swiftenv)?
  • JetBrains Toolbox (Webstorm, IntelliJ, etc): brew cask install jetbrains-toolbox
  • Xcode: ~/.dotfiles/xcode/install.sh (TODO: update this?)
  • SourceTree: brew cask install sourcetree (similar to gitkraken but free)
    • Open Terminal and create a new symlink to /usr/local/bin/gpg called gpg2
      • ln -s /usr/local/bin/gpg /usr/local/bin/gpg2
    • Preferences -> Advanced -> GPG Program
      • Set this to /usr/local/bin (it looks for a binary called gpg2 in this folder)
    • For each repository, in Repository -> Repository Settings -> Security
      • check "Enable GPG signing for commits" and select the appropriate key ID
      • if this option is disabled, you probably need to symlink the gpg2 binary as described above
  • GitKraken: brew cask install gitkraken (similar to SourceTree)
  • Etc
    • brew cask install aws-vault
    • brew cask install docker
    • brew cask install postman
    • brew cask install insomnia (optional, similar to postman)

Web Browser

  • Web Browser: brew cask install google-chrome
    • (Optional) brew cask install chrome-remote-desktop-host
    • Open Google Chrome, sign in to your google account and enable sync
      • Depending on the size of your profile, this could take a few minutes to sync and pull all of your bookmarks, extensions, etc across
    • It seems some extensions won't sync their preferences properly, so you may have to manually export/sync/re-configure them
      • LastPass
        • For some reason this extension didn't automatically install itself, so I had to re-add it manually
        • You just need to log into your account for settings/sync
      • Proxy SwitchyOmega (can import/export)
  • TODO: move this higher on the list of priorities?

Alfred

  • brew cask install alfred
    • Follow instructions in the setup wizard to add powerpack licence key, restore backed up settings, etc
    • Settings -> Advanced -> Syncing -> Set preferences folder
      • Depending how you sync your preferences (eg. Dropbox), you may need other apps installed before you can properly configure this
    • See also:
    • https://appsliced.co/ask/how-do-i-change-the-keyboard-shortcut-for-spotlight-in-os-x
      • System Preferences -> Spotlight -> Keyboard shortcuts
        • Disable Show spotlight search
    • Then configure desired shortcut (eg. command+space) in Alfred's settings
      • Settings -> General -> Alfred Hotkey
  • There are some settings that don't appear to be backed up/synced, we can configure these manually
    • Settings -> Features -> Web Bookmarks
      • check "Google Chrome Bookmarks"
    • Settings -> Features -> Clipboard History
      • check "Keep Plain Text" and select "24 hours"

BetterTouchTool

  • brew cask install bettertouchtool
    • Settings can be backed up/restored manually, or with a highly experimental 'sync' mode
      • In my experience, the sync seems less than ideal, and may cause CPU to spin, so manual seems the better option for now
      • From the main app screen, top right corner, select the Preset dropdown
        • From here you can use the Export Highlighted or Import buttons
        • Import from where you saved your settings (eg. Dropbox -> Backup -> BetterTouchTool)
        • (optional) At this stage you may want to
          • set the newly imported preset as the Master Preset
          • delete the existing Default preset
          • rename your imported preset with this computer's name (eg. Default (THISCOMPUTER))
    • You may want to also customise some of the settings in the settings menu itself
      • Settings -> Standard Settings -> Basic -> Launch BetterTouchTool on Startup
      • `Settings -> Standard Settings -> Basic -> Allow crash log and anonymised usage data
      • Settings -> Advanced Settings -> General -> Enable automatic update checking
      • Settings -> Advanced Settings -> General -> Install Process Priority Helper Tool
      • Settings -> Advanced Settings -> Scripting BTT -> Allow External BetterTouchTool Scripting
        • If you enable this, make sure to set the shared secret as well
      • Settings -> Advanced Settings -> Sync
        • Good to know this exists, but at the moment it doesn't seem particularly stable/useful, so maybe leave it disabled and backup/sync manually

Bartender

  • brew cask install bartender

Hyperdock

  • brew cask install hyperdock

Unsorted

The following don't have any complex setup scripts/environment required, so we can just manually install them with HomeBrew if desired:

  • brew cask install XXX
    • Core system tools
      • disk-inventory-x
      • flux
      • gemini (duplicate file finder)
    • Security/etc
      • viscosity
      • lastpass
    • Download
      • dropbox
      • resilio-sync
    • Organisation
      • fantastical
        • Make sure to add your Fantastical 2 licence (if you have one) to unlock all of the old features without requiring a monthly subscription
        • Preferences -> Accounts
          • Make sure to sign in to all your accounts (Flexibits, iCloud, Google, Todoist, Meetup, etc)
        • Preferences -> Accounts -> Open maps in -> Google Maps
        • etc
        • [fantastical] Automatically export/configure defaults/settings dotfiles#14
      • toggl
    • Communication
      • discord
      • signal
      • skype
      • telegram
      • zoomus
    • TODO: Facebook Messenger, WhatsApp, etc?
    • Audio/Video
      • lastfm (optional)
      • plexamp
      • spotify
      • vlc
    • Audio Production
      • blackhole
      • native-access
      • soundflower
      • We can't install these with homebrew, so grab them manually
    • Games
      • sidequest
      • sony-ps4-remote-play
      • steam
  • brew install XXX (a small selection, see brew.*.list files for more)
    • aria2
    • awscli
    • coreutils
    • dive
    • exiftool
    • ffmpeg
    • git
    • gnupg
    • go
    • gobuster
    • goreleaser
    • hub
    • jq
    • pcre
    • qemu
    • unrar
    • watchman

Unsorted

App Store

We also want to open the App Store, and install any past purchases we want on this machine:

  • Open App Store
  • Login with your Apple ID if you haven't already
  • Click on your account name in the bottom left-hand corner
  • The Account page should list any past purchases under the Purchased heading
    • Click the download icon for any you want to install
  • If you want to install Xcode, search for the latest version, and click install

Launchpad

Next we want to organise applications in Launchpad into appropriate folders. While this is controlled by a sqlite database, I'm not currently aware of any tools that allow us to do this automatically, so we'll do it manually for now:

  • TODO: list folder names I tend to use, in order they would be (top left, moving right/down)

Cleaning up an old laptop before selling/disposing

Unsorted

Legacy

Metadata

Metadata

Assignees

Labels

blog-ideaAn idea for a blog post and possibly related references/materials (use deep-dive if no blog planned)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions