From 328dd5004eaac5509d7e24359362df65c951478e Mon Sep 17 00:00:00 2001 From: Ankit Kumar Date: Sun, 21 Nov 2021 15:59:39 +0530 Subject: [PATCH] [Fix] `nvm_get_download_slug`: better architecture selection for M1 Macs If the node version is below 16.0.0 then nvm will select x86_64 architecture, else arm64 architecture. --- README.md | 2 ++ nvm.sh | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 4f2b588..94599b7 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,8 @@ If the above doesn't fix the problem, you may try the following: - For more information about this issue and possible workarounds, please [refer here](https://github.com/nvm-sh/nvm/issues/576) +**Note** For Macs with the M1 chip, node started providing **arm64** arch darwin packages since v16.0.0. For earlier versions, there were only **darwin_x64** packages available but no **darwin_arm64**. If you are facing issues installing node using `nvm`, you may want to update to v16 or later. + #### Ansible You can use a task: diff --git a/nvm.sh b/nvm.sh index f65e991..a37e422 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2093,6 +2093,14 @@ nvm_get_download_slug() { fi fi + # If node version in below 16.0.0 then there is no arm64 packages available in node repositories, so we have to install "x64" arch packages + # If running MAC M1 :: arm64 arch and Darwin OS then use "x64" Architecture because node doesn't provide darwin_arm64 package below v16.0.0 + if nvm_version_greater '16.0.0' "${VERSION}"; then + if [ "_${NVM_OS}" = '_darwin' ] && [ "${NVM_ARCH}" = 'arm64' ]; then + NVM_ARCH=x64 + fi + fi + if [ "${KIND}" = 'binary' ]; then nvm_echo "${FLAVOR}-${VERSION}-${NVM_OS}-${NVM_ARCH}" elif [ "${KIND}" = 'source' ]; then