Transitioning from Win to Mac 2- Managing ARM and x86 nodeJS and Python versions

Open Sauce Projects - Nov 2 - - Dev Community
  • 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:
    1. Edit the terminal user profile with nano or any other terminal file editor: nano ~/.zshrc
    2. 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"
Enter fullscreen mode Exit fullscreen mode
  • 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:
    1. Create the environment with following command: conda create -n my_x86_env -y
    2. You can active the environment with the command like this: conda activate my_x86_env
    3. 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
    4. Then you can install python conda install python=3.9 you can search for available python version with conda search python
    5. Now your env is ready for installing packages

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:
    1. The architecture will depend on what terminal you in, so if you want x86 use the "x86" command we discussed earlier
    2. 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
    3. To check the current version of node use: node -v
    4. 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 type nvm use 20

Happy coding!

Sources

. . . . . . . .