Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] nvm_get_download_slug: better architecture selection for M1 Macs #2657

Merged
merged 2 commits into from
Dec 3, 2021
Merged

[Fix] nvm_get_download_slug: better architecture selection for M1 Macs #2657

merged 2 commits into from
Dec 3, 2021

Conversation

imaddi47
Copy link
Contributor

@imaddi47 imaddi47 commented Nov 20, 2021

Changed configuration in nvm_get_download_slug() function, made condition for darwin based OS running on arm64 arch i.e, MAC M1.
If so, then change HOST_ARCH to x64 so that NVM will fetch x64 arch package from node repository which is the only package node currently having for darwin systems but no arm64 based packages

Problem

  • Macbook M1 ARM64 architecture problem that does not allow us to use default terminal for installing node packages using nvm, please refer here
  • What we did was use a rosetta-2 terminal for installing different node versions using NVM. It was creating problems for automation developers who use scripts to run operations, and it was not always possible to run the script on a single installed version of the node.
  • Even by transforming the current shell to a different arch using rosetta2 e.g, arch -x86_64 zsh causing problems as it creates a new instance of the terminal that is indirectly equivalent to using a different terminal i.e, rosetta one, which stops execution of next series of commands if it is invoked inside the script

Solutions Available

  • Use the latest version node as old ones were not built for mac m1 arch.
  • Use rosetta2 terminal to install node version as it converts architecture from arm64 to amd64, which then nvm install node packages for amd64
  • Solution Provided by me for automation engineers who don't want to switch on rosetta2 terminal just for installing node versions, Please refer this. Complete consequences explained in detail

Solution

  • Made changes in nvm.sh file to update nvm_get_download_slug() function that basically gathers architecture information regarding users system.
  • Basically rosetta was only being used to change architecture so that nvm_get_download_slug() would get x86_64 instead of arm64 architecture. Because older versions were never designed for arm64 architectures.
  • This part was the pain and I added conditions for the same, so that if the device is apple-based with silicon chip then it will set "x64" arch. So that packages fetched from the nodejs repository will be installed properly.

NVM working on mac m1 after making PR changes in nvm.sh

Problem solved after refreshing changes

  • First I have run "uname -a" to show my mac m1 architecture
  • Then I am trying to install node 12.22.7 nvm install 12.22.7 on arm64 arch. This throws me an error as the package was not found.
  • Then I sourced the RC file so that my changes in nvm.sh reflect in the shell. Whoop, this worked

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

nvm.sh Outdated Show resolved Hide resolved
nvm.sh Outdated Show resolved Hide resolved
@ljharb ljharb added installing node Issues with installing node/io.js versions. OS: Mac OS labels Nov 20, 2021
@imaddi47 imaddi47 requested a review from ljharb November 21, 2021 00:03
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
nvm.sh Outdated Show resolved Hide resolved
nvm.sh Outdated Show resolved Hide resolved
If the node version is below 16.0.0 then nvm will select x86_64 architecture, else arm64 architecture.
nvm.sh Outdated Show resolved Hide resolved
@imaddi47 imaddi47 requested a review from ljharb November 21, 2021 17:48
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Does perhaps the section in the readme that talks about Rosetta need to be updated now?

@imaddi47
Copy link
Contributor Author

Thanks! Does perhaps the section in the readme that talks about Rosetta need to be updated now?

I don't think this is the right time to do so. Perhaps most of the developers already installed the current version of nvm and do not bother updating fixes.
I think still most of the developers will be finding solutions for manual installing nodes using the nvm version installed to their systems, and README.me will definitely gonna help them. If they really will fix that issue permanently then they will go through this discussion.

Removing talks about Rosetta in the next version upgrades would be better. For now, we can put a note governing to upgrade nvm in the Rosetta section. Hope this makes sense!!

@ljharb ljharb changed the title Solved/Automated NVM for MAC M1 arm64 arch problem, Now no need to use Rosetta for node installation [Fix] nvm_get_download_slug: better architecture selection for M1 Macs Dec 3, 2021
@ljharb ljharb merged commit 81fc056 into nvm-sh:master Dec 3, 2021
@imaddi47 imaddi47 deleted the nvm-macm1-fix/arm64-compatibility branch December 3, 2021 18:17
@kerberw
Copy link

kerberw commented Jan 2, 2024

Thanks! Does perhaps the section in the readme that talks about Rosetta need to be updated now?

I don't think this is the right time to do so. Perhaps most of the developers already installed the current version of nvm and do not bother updating fixes. I think still most of the developers will be finding solutions for manual installing nodes using the nvm version installed to their systems, and README.me will definitely gonna help them. If they really will fix that issue permanently then they will go through this discussion.

Removing talks about Rosetta in the next version upgrades would be better. For now, we can put a note governing to upgrade nvm in the Rosetta section. Hope this makes sense!!

I think Maybe it is the right time to update the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installing node Issues with installing node/io.js versions. OS: Mac OS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants