Clean install of MacOS High Sierra

Fri 17 November 2017 — Filed under notes; tags: mac

I make it a practice to blow away previous versions of the OS and start with a clean install each time there's a major update. Why do this?

  • In my experience, clean installs result in a more stable system.
  • I try to maintain a system that is easily bootstrapped, and this is pretty much the only way to reliably test that process.
  • I want to make sure that everything that I really care about on my computer is replicated someplace, either using a cloud service (mostly Dropbox), or in git repositories. This forces the issue.

Once again, homebrew is the foundation of my setup. I used homebrew to install not only command line programs and languages (python, R), but also as many desktop apps as I could (Chrome, x11) that would otherwise have been installed manually by hunting down an installer. Each time I go through this, homebrew takes care of more and more apps.

Somewhat glossed over here are manual steps used to transfer non-public dotfiles, credentials, etc. Here's a partial list of files and directories that I copied directly from my old laptop:

tar -cf dotfiles.tar .Xmodmap .gitconfig .gnupg .pypirc .ssh

Note that none of these steps require an Apple ID - I held off on signing in until the very end just to see if it was possible.

system settings

turn off spelling autocorrect

System Preferences --> Keyboard --> Text tab --> unselect "Correct spelling automatically" and others

unmap Control + left,right

I use Control plus the left and right arrow keys to move between windows in emacs and tmux.

System Preferences --> Keyboard --> Shortcuts --> uncheck mission control: move left/right a space

Turn on FileVault

System Preferences --> Security & privacy --> FileVault

I used a recovery key option rather than iCloud for my work machine, iCloud for personal

Developer tools

Pretty much the first thing that needs to happen. This can be done from the command line:

xcode-select --install

homebrew

Homebrew no longer requires user-ownership of /usr/local, so things are pretty easy now:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor

Many packages are installed later with additional elaboration or in as dependencies for other applications; here are some more or less standalone packages that I routinely install.

brew install git && \
brew install wget && \
brew install autojump && \
brew install gcc && \
brew install graphviz && \
brew install latex2rtf && \
brew install pandoc && \
brew install tmux && \
brew install tree && \
brew install fd && \
brew install xsv

homebrew API token

Apparently lots of requests to GutHub via homebrew can hit a rate limit. There's a higher limit if you create an API token. See https://gist.github.com/christopheranderton/8644743

Here's the url for the token creation dialog:

https://github.com/settings/tokens/new?scopes=&description=Homebrew

Make sure that all 'scopes' are unchecked. Once you generate the token, add to your shell profile:

export HOMEBREW_GITHUB_API_TOKEN=token_here

python

I'm in the midst of the transition from python2 to python3, so as I wrote this it wasn't clear which packages (if any) I would need to install to the system. I decided to go with mostly python3, and really tried to limit these to utilities that are used outside of the context of a virtualenv.

Use homebrew - see https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md

dependencies

Run brew info python for required and optional dependencies

for pkg in sphinx-doc pkg-config readline sqlite gdbm berkeley-db@4 tcl-tk; do brew install $pkg; done

python2

brew install python@2 --with-tcl-tk
/usr/local/bin/pip2 install -U pip setuptools virtualenv wheel

python3

Note that "python" corresponds to the python3 homebrew recipe.

brew install python --with-tcl-tk
/usr/local/bin/pip3 install -U pip wheel

A limited selection of packages - better to use virtualenvs!

pip3 install ansible
pip3 install csvkit
pip3 install pgcli

scons

Note that scons wants to install man pages to /usr/local/man, which is owned by root. You'll need to do this first:

sudo mkdir -p /usr/local/man
sudo chown $(whoami) /usr/local/man
pip3 install scons

emacs

Install latest emacs binary from http://emacsformacosx.com/

Emacs needs a few homebrew packages

brew install libressl
brew install aspell
brew install gpg

Check out my .emacs.d and run setup scripts.

cd ~
git clone --recurse-submodules git@github.com:nhoffman/.emacs.d.git

For elpy:

cd ~/.emacs.d
bin/venv.sh

zsh

Install zsh with Homebrew

brew install zsh

Change shell to zsh

sudo -s
echo /usr/local/bin/zsh >> /etc/shells
exit
chsh -s /usr/local/bin/zsh $USER

Install my dotfiles (relevant only to me)

cd ~
git clone git@bitbucket.org:nhoffman/dotfiles.git
~/dotfiles/mac/install.py

desktop apps

Homebrew installs desktop apps too!

brew cask install dropbox
brew cask install sizeup
brew cask install dash
brew cask install hipchat
brew cask install google-chrome
brew cask install java
brew cask install mactex
brew cask install texmaker
brew cask install wkhtmltopdf
brew cask install firefox
brew cask install docker

Some of the above (eg, sizeup, dropbox, dash) require licenses and credentials that must be installed interactively.

iTerm2

brew cask install iterm2

Update a few settings.

Preferences –> Profiles –> Keys and do these things:

  • select "Left/right option key acts as": +Esc
  • + –> Keyboard shortcut "OPT+<left arrow>": Send Escape sequence "b"
  • + –> Keyboard shortcut "OPT+<right arrow>": Send Escape sequence "f"

Default appearance:

  • Preferences –> Profiles –> Colors –> Load Presets –> Light Background
  • Preferences –> Profiles –> Text –> Change Font –> 14 point

postgresql

brew cask install postgres

This installs multiple versions of postgres. You'll need to add the path to the CLI for the version you want to use to your PATH, eg:

export PATH=/Applications/Postgres.app/Contents/Versions/9.6/bin:$PATH

R

Again, using homebrew.

brew install openblas
brew install pcre
brew install R

Some packages that I know I'll need:

R --slave << EOF
packages <- c("lattice", "RSQLite", "latticeExtra", "argparse", "data.table", "tidyverse")
install.packages(packages, repos="http://cran.fhcrc.org/", dependencies=TRUE, clean=TRUE, Ncpus=4)
EOF

Wow, this takes a long time!

And while I'm at it:

brew cask install rstudio

X11

install Xquartz

brew install caskroom/cask/xquartz

X11 key bindings so that the option key is used for Meta. Not so relevant any more now that I rarely use emacs via X11 for remote sessions.

cat > ~/.Xmodmap <<EOF
clear Mod1
clear Mod2
keycode 63 = Mode_switch
keycode 66 = Meta_L
add Mod1 = Meta_L
add Mod2 = Mode_switch
EOF

virtualbox and vagrant

brew cask install virtualbox
brew cask install vagrant
brew cask install vagrant-manager

On High Sierra, a kernel extension signing issue caused an error: instructions for a workaround are here: https://github.com/caskroom/homebrew-cask/issues/39369

After virtualbox is installed, go to preferences, and change default machine folder to ~/VirtualBox

  • available vagrant images:

https://app.vagrantup.com/boxes/search

install an ubuntu16.04 VM

see https://app.vagrantup.com/ubuntu/boxes/xenial64

mkdir -p ~/vagrant/xenial64
cd ~/vagrant/xenial64
vagrant init ubuntu/xenial64
vagrant up