Skip to content

Instantly share code, notes, and snippets.

@kirankotari
Last active January 12, 2023 19:27
Show Gist options
  • Save kirankotari/e7987f01d0421e43f9535aaf9b74d3f7 to your computer and use it in GitHub Desktop.
Save kirankotari/e7987f01d0421e43f9535aaf9b74d3f7 to your computer and use it in GitHub Desktop.
How to use Mac M1/M2 (arm64) to x86_64 (like Intel)

How to use Mac M1/M2 (arm64) to x86_64 (like Intel)

  1. Uninstall all previous installation and its dependencies, e.g. ant, Java,..
brew remove java
brew remove ant
brew remove zlib
# python, etc

remove homebrew last

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

rm -rf /opt/homebrew

Note Finalling removing homebrew if you installed them in M1/M2 i.e. via arm64 (default)

  1. run the following command to install Rosetta (which is an emulator, that converts M1/M2 to x86_64)
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
  1. add the following to your .bashrc and source the file
#!/usr/bin/env bash
export PATH="/usr/bin:/usr/local/bin:$PATH"

# GIT FUNCTIONS
git_branch() {
    git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# TERMINAL PROMPT
get_m1_ps1() {
    echo "\[\e[0;92m\]\$(git_branch)\[\e[m\] \n\[\e[0;93m\](m1) \u\[\e[m\] \[\e[0;95m\]\W\[\e[m\] >> "
}
get_intel_ps1() {
    echo "\[\e[0;92m\]\$(git_branch)\[\e[m\] \n\[\e[0;93m\](intel) \u\[\e[m\] \[\e[0;95m\]\W\[\e[m\] >> "
}
get_amd_ps1() {
    echo "\[\e[0;92m\]\$(git_branch)\[\e[m\] \n\[\e[0;93m\](amd64) \u\[\e[m\] \[\e[0;95m\]\W\[\e[m\] >> "
}

case $(uname -m) in
    x86_64) PS1=$(get_intel_ps1) ;;
    arm64)    PS1=$(get_m1_ps1) ;;
esac

export PS1=$PS1

# arch
alias arm="env /usr/bin/arch -arm64 /bin/bash --login"
alias intel="env /usr/bin/arch -x86_64 /bin/bash --login"

export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

  1. Switch to the x86_64 or arm64 architecture by running the following in the terminal
intel # x86_64
arm # arm64
  1. Install homebrew from https://brew.sh/

  2. Run the following command

 brew install openssl readline sqlite3 xz zlib tcl-tk
  1. Add the following to .bashrc and source it
export PATH="/usr/local/opt/openssl@3/bin:$PATH"

export LDFLAGS+=" -L/usr/local/opt/openssl@3/lib"
export CPPFLAGS+=" -I/usr/local/opt/openssl@3/include"
export CFLAGS+=" -I/usr/local/opt/openssl@3/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@3/lib/pkgconfig"

export LDFLAGS+=" -L/usr/local/opt/readline/lib"
export CPPFLAGS+=" -I/usr/local/opt/readline/include"
export CFLAGS+=" -I/usr/local/opt/readline/include"

export PATH="/usr/local/opt/sqlite/bin:$PATH"

export LDFLAGS+=" -L/usr/local/opt/sqlite/lib"
export CPPFLAGS+=" -I/usr/local/opt/sqlite/include"
export CFLAGS+=" -I/usr/local/opt/sqlite/include"

export LDFLAGS+=" -L/usr/local/opt/zlib/lib"
export CPPFLAGS+=" -I/usr/local/opt/zlib/include"
export CFLAGS+=" -I/usr/local/opt/zlib/include"

export PATH="/usr/local/opt/tcl-tk/bin:$PATH"

export LDFLAGS+=" -L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS+=" -I/usr/local/opt/tcl-tk/include"
export CFLAGS+=" -I/usr/local/opt/tcl-tk/include" 
  1. Install pyenv using brew:
brew install pyenv
  1. Add following to .bash_profile and source it
# # Pyenv python
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"

eval "$(pyenv init -)" 
  1. Install python using pyenv, and verify cryptography install
pyenv install 3.8.9 --verbose
pyenv versions
pyenv global 3.8.9
pip install --upgrade pip
pip install wheel setuptools
pip install cryptography
  1. Install Java11
brew install java11

# Verify that JavaVirtualMachines folder exist in
ls /Library/Java

# then run
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
  1. Add the following to your .bashrc and source it
export PATH="/usr/local/opt/openjdk@11/bin:$PATH"

export CPPFLAGS+=" -I/usr/local/opt/openjdk@11/include"
export CFLAGS+=" -I/usr/local/opt/openjdk@11/include"
export JAVA_HOME="/usr/local/opt/openjdk@11" 
  1. run the following command
brew install ant@1.9

then add the following to you .bashrc and source it

export PATH="/usr/local/opt/ant@1.9/bin:$PATH" 

In Explore goto Application Folder, Right click on terminal and click on Get info Under Copyright: you need to tick "Open using Rosetta"

Now close and open terminal and its done. Now you can use your Mac M1/M2 as a Intel. I hope you wont be facing issues while installing any Applications. Hurray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment