# Rosetta2
❯ softwareupdate --install-rosetta --agree-to-license
# Command Line Tools(including python3, clang and other useful libraries)
❯ xcode-select --install> sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"Notable Themes:
powerlevel10k is an awesome-looking theme for Zsh which can actually make your shell faster!
Configuring ~/.zshrc:
alias leg="arch -x86_64 zsh" # alias enter Rosetta terminalOr if using many Alias and PATH setting, it's better to put them into a ~/.profile file, and add it to ~/.zshrc:
# before `~/.p10k.zsh`
[[ ! -f ~/.profile ]] || source ~/.profile
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zshadd cpu_arch into POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS in ~/.pk10k.zsh to show whether x86 or arm cpu arch in mac m1.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
...
cpu_arch # CPU architecture
...
)-
Native Homebrew
❯ arch --arm64 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"all Homebrew related stuffs are in
/opt/homebrew. -
Rosetta Homebrew
❯ arch --x86_64 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"all Homebrew related stuffs are in
/opt/local.
To switch between native and intel-emulated Homebrews based on different working architecture, you can add following into ~/.zshrc,
Configuring ~/.zshrc:
if [ "$(arch)" = "arm64" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fiSo, in Rosetta terminal, we will have brew linked to /usr/local/bin/brew,
❯ leg
❯ arch
i386
❯ which brew
/usr/local/bin/brewMirrors:
Python3.8 and Python3.9 are natively supported in Applie Silcon,
❯ arch
arm64
❯ brew install python@3.8 python@3.9
❯ file /opt/homebrew/opt/python@3.8/bin/python3
/opt/homebrew/opt/python@3.8/bin/python3: Mach-O 64-bit executable arm64Python3.7, however and other belows will never be supported on Apple Silicon:
NOTE: There are no plans to backport support to 3.7 and 3.6 which are in the security-fix-only phase of their release cycles.
❯ leg
❯ arch
i386
❯ brew install python@3.7
❯ file /usr/local/opt/python@3.7/bin/python3
/usr/local/opt/python@3.7/bin/python3.7: Mach-O 64-bit executable x86_64Configure ~/.zshrc:
if [ "$(arch)" = "arm64" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
export PATH="/opt/homebrew/opt/python@3.8/bin:$PATH"
export PATH="/opt/homebrew/opt/python@3.9/bin:$PATH"
else
eval "$(/usr/local/bin/brew shellenv)"
export PATH="/usr/local/opt/python@3.7/bin:$PATH"
fi# useful Python C-library compliation 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"Native nvm,
❯ arch
arm64
❯ brew install nvmConfigure ~/.zshrc:
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_completionHere is the aim to install both arm64 and x64 respectively.
-
Download .NET from website respectively for
arm64andx64version, the former will be installed into"/usr/local/share/dotnet"and the later will be in"/usr/local/share/dotnet/x64". -
Delete the
dotnetenvironment settingPATH, otherwise it will always prepend thearm dotnetpath in first.❯ cat /etc/paths.d/dotnet /usr/local/share/dotnet ❯ rm -rf /etc/paths.d/dotnet
NOTE: this is because
/usr/libexec/path_helpermakes the trouble in macOS. -
Configure
~/.zshrcto use arm64 and x64dotnet:# Multiple Homebrews on Apple Silicon if [ "$(arch)" = "arm64" ]; then eval "$(/opt/homebrew/bin/brew shellenv)" export DOTNET_ROOT="/usr/local/share/dotnet" export PATH="$DOTNET_ROOT:~/.dotnet/tools:$PATH" else eval "$(/usr/local/bin/brew shellenv)" export DOTNET_ROOT="/usr/local/share/dotnet/x64" export PATH="$DOTNET_ROOT:~/.dotnet/tools:$PATH" fi
How to migrate to native Homebrew on an M1 Mac
Python, Django, and React Development on Apple Silicon
My Ultimate M1 Mac Developer Setup
Properly setting $PATH for zsh on macOS (fighting with path_helper) · GitHub