# 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 terminal
Or 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.zsh
add 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)"
fi
So, in Rosetta terminal, we will have brew
linked to /usr/local/bin/brew
,
❯ leg
❯ arch
i386
❯ which brew
/usr/local/bin/brew
Mirrors:
Python3.8 and Python3.9 are natively supported in Applie Silcon,
❯ arch
arm64
❯ brew install [email protected] [email protected]
❯ file /opt/homebrew/opt/[email protected]/bin/python3
/opt/homebrew/opt/[email protected]/bin/python3: Mach-O 64-bit executable arm64
Python3.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 [email protected]
❯ file /usr/local/opt/[email protected]/bin/python3
/usr/local/opt/[email protected]/bin/python3.7: Mach-O 64-bit executable x86_64
Configure ~/.zshrc
:
if [ "$(arch)" = "arm64" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
else
eval "$(/usr/local/bin/brew shellenv)"
export PATH="/usr/local/opt/[email protected]/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 nvm
Configure ~/.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_completion
Here is the aim to install both arm64 and x64 respectively.
-
Download .NET from website respectively for
arm64
andx64
version, the former will be installed into"/usr/local/share/dotnet"
and the later will be in"/usr/local/share/dotnet/x64"
. -
Delete the
dotnet
environment settingPATH
, otherwise it will always prepend thearm dotnet
path in first.❯ cat /etc/paths.d/dotnet /usr/local/share/dotnet ❯ rm -rf /etc/paths.d/dotnet
NOTE: this is because
/usr/libexec/path_helper
makes the trouble in macOS. -
Configure
~/.zshrc
to 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