The Apple M1 and M2
Historically our dev workflows and setup have revolved around x86 architecture. The M1 is new and can be a bit of a problem setting up. As you work through this process, please update this doc with quirks, tricks, or best practices you come across.
These instructions are currently the same for both M1 and M2.
Warning
As of the commit of this documentation, the following blog is the best place to start. Forge your own path at your and your colleagues risk. Right now it is very easy to get into a state where confusing things happen.
Colin's blog post Python, Django, and React Development on Apple Silicon.
Another post Django Development Environment on Apple M1
Environment setup
Rosetta 2 and Xcode
First, make sure Rosetta 2 is installed. Rosetta 2 enables a Mac with Apple silicon to use apps built for a Mac with an Intel processor. Install it with:
softwareupdate --install-rosetta --agree-to-license
Also, install Xcode's command-line tools for python3
and other useful libraries:
xcode-select --install
Generating a new SSH key
Follow GitHub's Generating a new SSH key and adding it to the ssh-agent instructions for these sections:
- Generating a new SSH key
- Adding your SSH key to the ssh-agent
ssh-agent
In MacOS Monterey (12.0) or later, you should use the --apple-use-keychain
to add your SSH private key to the ssh-agent and store your passphrase in the keychain:
ssh-add --apple-use-keychain
Configure Git name and email
GitHub uses your commit email address to associate commits with your account on GitHub.com. Follow these steps to link your git configuration to your GitHub account.
First add, verify, and set as Primary your Caktus email on GitHub.
To associate your git
commits to your GitHub account, we will set your name and email address for every repository on your computer.
-
Set your name:
git config --global user.name "Mona Lisa"
-
Then set your email:
git config --global user.email "mlisa@caktusgroup.com"
Homebrew
Homebrew does support Apple Silicon.
Install arm64 brew
into /opt/homebrew
:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then add brew
to your PATH:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
Note
It seems that Homebrew packages have now generally added support for arm64. However, it is possible that you may encounter a package that does not. If you find yourself in that scenario, it is possible to support running both native arm64 and x86-emulated homebrew packages, by installing an x86-emulated homebrew side-by-side. See Colin's blog post for an example.
Install openssl
brew install openssl
Starship Prompt
Starship is a simple and customizable shell prompt. Follow the Quick Install instructions to get set up.
Note
Make sure to install a Nerd Font to render glyph symbols (, ) properly. Then enable the font in your terminal:
- iTerm2: Open iTerm2 → Preferences → Profiles → Text and set Font to your Nerd Font.
- Visual Studio Code: Open Code → Preferences → Settings (Mac), enter
terminal.integrated.fontFamily
in the search box at the top of Settings ta and set the value below to your Nerd Font.
Install Python
We recommend installing Python from the python.org Downloads page.
After running through the installation, don't forget to double click on the Install Certificates.command icon in Finder (in the folder for the new Python installation) to install a set of SSL root certificates.
Note
You may instead use a Python manager (like pyenv) to manager versions of Python, if you prefer, though our experience with them has not been as good as downloading Python from python.org.
Install direnv
Next install direnv, which will load/unload environment variables based on a .envrc
file.
brew install direnv
In your user's Home directory create a file .direnvrc
$> touch ~/.direnvrc
Then edit that file and add the following to it using your favorite text editor, and add the following.
use_cluster() {
kubectl config use-context "$1"
}
Add the following lines to your ~/.zshrc
:
eval "$(direnv hook zsh)"
Install PostgreSQL
Even if you don't run the PostgreSQL service, it can be helpful to install the CLI tools with:
HOMEBREW_NO_AUTO_UPDATE=1 brew install postgresql
Note
See From Caktus With Love for more information on HOMEBREW_NO_AUTO_UPDATE=1
.
Install Docker
Visit https://docs.docker.com/desktop/mac/install/ and click the Mac with Apple chip blue button, then:
- Once downloaded, copy the Docker application to your Applications folder
- Then open the Docker app in the Applications folder
Currently Identified Additions to .zshrc for M1 Users
alias ibrew='arch -x86_64 /usr/local/bin/brew'
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
# Add homebrew to path
export PATH="/opt/homebrew/bin:$PATH"
# C-lib compilation flags
export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix zlib)/lib"
export CPPFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix zlib)/include"
# Hook in direnv
eval "$(direnv hook zsh)"
After adding this to your `.zshrc`, source the file to make it available to your current
environment.
```shell
$> source ~/.zshrc