- Lot of python and NodeJS packages are compatible with ARM but not all, from a performance perspective you better of using an ARM native software.
- So you might run into scenarios where you need a certain version of Python or NodeJS in both it's ARM and x86 version, i will attempt to give a solution for these problems in this article without costing ARM or a leg.
Launching a "x86 terminal"
- It is possible to launch a terminal session where all commands will go through rosetta 2 here are the steps to achieve that:
- Edit the terminal user profile with nano or any other terminal file editor: nano ~/.zshrc
- Add the following lines to the file:
alias arm="env /usr/bin/arch -arm64 /bin/zsh --login"
alias x86="env /usr/bin/arch -x86_64 /bin/zsh --login"
- In this way if you type the "intel" command into the terminal you will get an x86 session, if you write the "arm" command you will get and a native not emulated ARM session.
- This will be needed when installing the x86 version of NodeJS.
Managing Python versions
- Creating and managing python environments is made easier using miniconda, which can be installed like this: brew install miniconda
- conda is like a python virtual environment you can install packages into it using the conda install command or use pip
- Here are steps to create a python environment with miniconda:
- Create the environment with following command:
conda create -n my_x86_env -y
- You can active the environment with the command like this:
conda activate my_x86_env
- You need to set which architecture you want to use for x86:
conda config --env --set subdir osx-64
for arm:replace osx-64 with osx-arm64
but if you don't specify the architecture it will use ARM as a default - Then you can install python
conda install python=3.9
you can search for available python version withconda search python
- Now your env is ready for installing packages
- Create the environment with following command:
Managing NodeJS versions
- For this we gonna use nvm which is version manager for node, this can be installed with brew: brew install nvm
- Here is list of useful nvm commands
- Steps to get you going:
- The architecture will depend on what terminal you in, so if you want x86 use the "x86" command we discussed earlier
- Install node:
nvm install VERSION
you can't install the exact same version in both architectures but you can install slightly older or newer one - To check the current version of node use:
node -v
- For switching between the versions:
nvm use VERSION
command. Fun fact when switching versions you don't need to specify the version number exactly for example if i want to switch to 20.16.0, I just have to typenvm use 20
Happy coding!
Sources
- https://stackoverflow.com/questions/71691598/how-to-run-python-as-x86-with-rosetta2-on-arm-macos-machine
- https://stackoverflow.com/questions/39604271/conda-environments-not-showing-up-in-jupyter-notebook
- https://stackoverflow.com/questions/75942145/how-to-quickly-change-between-arm64-or-x86-architecture-in-m1-m2-mac-terminals