改善
Kaizen  Today I Learned by Ville Säävuori

Setting Up macOS for Web Development

Getting your development environment running and configured has become much easier over time but it’s still a hassle to get everything set up and configured from scratch. These notes are a continuously evolving task list for my personal setup.

Applications

Terminal

Git

Terminal window
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git config --global init.defaultBranch main

Node

Node is almost as bad as Python with different versions so using nvm is a must. After installing it with brew, install few of the necessary versions and then set the default:

Terminal window
nvm install 12
nvm install 14
nvm install 16
nvm alias default 16

Now the default version does not use the latest node but the latest 16.x instead. Whenever a project needs different version, just say nvm use x to activate the needed version.

Python

To minimize XKCD 1987 the best way to handle Python versions is to only use pyenv. So brew install pyenv (and brew install pyenv-virtualenv). Then, importantly, add both of these lines to make sure pyenv is loaded for new terminal sessions automatically:

Terminal window
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
echo 'eval "$(virtualenv-init init -)"' >> ~/.zshrc

Now just install the latest usable (ie. not the point zero version of a new release) Python version and set it as global default.

Poetry is easiest to install with the installation script.

Postgis / GDAL / GEOS

Previously I haven’t had much problem with these as they install easily with Homebrew, but on macOS Monterey and Apple Silicon (M1) I had to add these to Django settings to get them working:

GDAL_LIBRARY_PATH = '/opt/homebrew/opt/gdal/lib/libgdal.dylib'
GEOS_LIBRARY_PATH = '/opt/homebrew/opt/geos/lib/libgeos_c.dylib'