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

nvm install node fails to install on macOS Big Sur M1 Chip #2350

Closed
andyaccelerate opened this issue Nov 17, 2020 · 69 comments · Fixed by #2416
Closed

nvm install node fails to install on macOS Big Sur M1 Chip #2350

andyaccelerate opened this issue Nov 17, 2020 · 69 comments · Fixed by #2416
Labels
installing node Issues with installing node/io.js versions. OS: Mac OS pull request wanted This is a great way to contribute! Help us out :-D

Comments

@andyaccelerate
Copy link

andyaccelerate commented Nov 17, 2020

I'm trying to install the latest version of node using nvm. I've just got the newly released SIlicon Macbook Pro with the M1 chip (not sure if that is related). I've installed xcode on the app store and the xcode tools on the command line. The main error i'm getting is:

clang: error: no such file or directory: 'CXX=c++'

Full command output is at the bottom of the page.

Any help appreciated,
Thanks

Operating system and version:

MacOS Big Sur

nvm debug output:

nvm --version: v0.33.0
$SHELL: /bin/zsh
$HOME: /Users/andy
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: none
which node: node not found
which iojs: iojs not found
which npm: npm not found
npm config get prefix: nvm:119: command not found: npm
npm root -g: nvm:119: command not found: npm

nvm ls output:

N/A
node -> stable (-> N/A) (default)
iojs -> N/A (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.23.0 (-> N/A)
lts/erbium -> v12.19.1 (-> N/A)
lts/fermium -> v14.15.1 (-> N/A)

How did you install nvm?

install script in readme

What steps did you perform?

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
nvm install node

What happened?

Downloading and installing node v15.2.1...
Local cache found: $NVM_DIR/.cache/bin/node-v15.2.1-darwin-arm64/node-v15.2.1-darwin-arm64.tar.gz
Computing checksum with shasum -a 256
Provided checksum to compare to is empty.
Checksum check failed!
Removing the broken local cache...
Downloading https://nodejs.org/dist/v15.2.1/node-v15.2.1-darwin-arm64.tar.gz...
##O#-  #                                                                                                                        
Computing checksum with shasum -a 256
Provided checksum to compare to is empty.
tar: Error opening archive: Unrecognized archive format
Binary download failed, trying source.
Local cache found: $NVM_DIR/.cache/src/node-v15.2.1/node-v15.2.1.tar.gz
Checksums match! Using existing downloaded archive $NVM_DIR/.cache/src/node-v15.2.1/node-v15.2.1.tar.gz
Node.js configure: Found Python 2.7.16...
INFO: configure completed successfully
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C out BUILDTYPE=Release V=0
  LD_LIBRARY_PATH=/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/lib.host:/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../.; mkdir -p /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj/gen; dtrace -h -xnolibs -s src/node_provider.d -o "/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj/gen/node_provider.h"
  LD_LIBRARY_PATH=/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/lib.host:/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../.; mkdir -p /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release; tools/specialize_node_d.py "/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/node.d" src/node.d mac arm64
  touch /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/tools/icu/icu_implementation.stamp
  touch /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/tools/icu/icu_uconfig.stamp
  touch /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/tools/icu/icu_uconfig_target.stamp
  touch /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.host/tools/icu/icu_implementation.stamp
  touch /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.host/tools/icu/icu_uconfig.stamp
  cc CXX=c++ -o /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/bio_ssl.o ../deps/openssl/openssl/ssl/bio_ssl.c '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DOPENSSL_NO_HW' '-DOPENSSL_NO_QUIC=1' '-DNDEBUG' '-DL_ENDIAN' '-DOPENSSL_PIC' '-DOPENSSL_CPUID_OBJ' '-DOPENSSL_BN_ASM_MONT' '-DSHA1_ASM' '-DSHA256_ASM' '-DSHA512_ASM' '-DKECCAK1600_ASM' '-DVPAES_ASM' '-DECP_NISTZ256_ASM' '-DPOLY1305_ASM' '-DOPENSSLDIR="/System/Library/OpenSSL/"' '-DENGINESDIR="/dev/null"' -I../deps/openssl/openssl -I../deps/openssl/openssl/include -I../deps/openssl/openssl/crypto -I../deps/openssl/openssl/crypto/include -I../deps/openssl/openssl/crypto/modes -I../deps/openssl/openssl/crypto/ec/curve448 -I../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I../deps/openssl/config -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2 -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/include -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto/include/internal  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -Wno-missing-field-initializers -fno-strict-aliasing -MMD -MF /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/.deps//Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/bio_ssl.o.d.raw   -c
  cc CXX=c++ -o /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_lib.o ../deps/openssl/openssl/ssl/d1_lib.c '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DOPENSSL_NO_HW' '-DOPENSSL_NO_QUIC=1' '-DNDEBUG' '-DL_ENDIAN' '-DOPENSSL_PIC' '-DOPENSSL_CPUID_OBJ' '-DOPENSSL_BN_ASM_MONT' '-DSHA1_ASM' '-DSHA256_ASM' '-DSHA512_ASM' '-DKECCAK1600_ASM' '-DVPAES_ASM' '-DECP_NISTZ256_ASM' '-DPOLY1305_ASM' '-DOPENSSLDIR="/System/Library/OpenSSL/"' '-DENGINESDIR="/dev/null"' -I../deps/openssl/openssl -I../deps/openssl/openssl/include -I../deps/openssl/openssl/crypto -I../deps/openssl/openssl/crypto/include -I../deps/openssl/openssl/crypto/modes -I../deps/openssl/openssl/crypto/ec/curve448 -I../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I../deps/openssl/config -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2 -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/include -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto/include/internal  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -Wno-missing-field-initializers -fno-strict-aliasing -MMD -MF /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/.deps//Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_lib.o.d.raw   -c
  cc CXX=c++ -o /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_msg.o ../deps/openssl/openssl/ssl/d1_msg.c '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DOPENSSL_NO_HW' '-DOPENSSL_NO_QUIC=1' '-DNDEBUG' '-DL_ENDIAN' '-DOPENSSL_PIC' '-DOPENSSL_CPUID_OBJ' '-DOPENSSL_BN_ASM_MONT' '-DSHA1_ASM' '-DSHA256_ASM' '-DSHA512_ASM' '-DKECCAK1600_ASM' '-DVPAES_ASM' '-DECP_NISTZ256_ASM' '-DPOLY1305_ASM' '-DOPENSSLDIR="/System/Library/OpenSSL/"' '-DENGINESDIR="/dev/null"' -I../deps/openssl/openssl -I../deps/openssl/openssl/include -I../deps/openssl/openssl/crypto -I../deps/openssl/openssl/crypto/include -I../deps/openssl/openssl/crypto/modes -I../deps/openssl/openssl/crypto/ec/curve448 -I../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I../deps/openssl/config -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2 -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/include -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto/include/internal  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -Wno-missing-field-initializers -fno-strict-aliasing -MMD -MF /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/.deps//Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_msg.o.d.raw   -c
  cc CXX=c++ -o /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_srtp.o ../deps/openssl/openssl/ssl/d1_srtp.c '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DOPENSSL_NO_HW' '-DOPENSSL_NO_QUIC=1' '-DNDEBUG' '-DL_ENDIAN' '-DOPENSSL_PIC' '-DOPENSSL_CPUID_OBJ' '-DOPENSSL_BN_ASM_MONT' '-DSHA1_ASM' '-DSHA256_ASM' '-DSHA512_ASM' '-DKECCAK1600_ASM' '-DVPAES_ASM' '-DECP_NISTZ256_ASM' '-DPOLY1305_ASM' '-DOPENSSLDIR="/System/Library/OpenSSL/"' '-DENGINESDIR="/dev/null"' -I../deps/openssl/openssl -I../deps/openssl/openssl/include -I../deps/openssl/openssl/crypto -I../deps/openssl/openssl/crypto/include -I../deps/openssl/openssl/crypto/modes -I../deps/openssl/openssl/crypto/ec/curve448 -I../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I../deps/openssl/config -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2 -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/include -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto/include/internal  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -Wno-missing-field-initializers -fno-strict-aliasing -MMD -MF /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/.deps//Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_srtp.o.d.raw   -c
  cc CXX=c++ -o /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/methods.o ../deps/openssl/openssl/ssl/methods.c '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DOPENSSL_NO_HW' '-DOPENSSL_NO_QUIC=1' '-DNDEBUG' '-DL_ENDIAN' '-DOPENSSL_PIC' '-DOPENSSL_CPUID_OBJ' '-DOPENSSL_BN_ASM_MONT' '-DSHA1_ASM' '-DSHA256_ASM' '-DSHA512_ASM' '-DKECCAK1600_ASM' '-DVPAES_ASM' '-DECP_NISTZ256_ASM' '-DPOLY1305_ASM' '-DOPENSSLDIR="/System/Library/OpenSSL/"' '-DENGINESDIR="/dev/null"' -I../deps/openssl/openssl -I../deps/openssl/openssl/include -I../deps/openssl/openssl/crypto -I../deps/openssl/openssl/crypto/include -I../deps/openssl/openssl/crypto/modes -I../deps/openssl/openssl/crypto/ec/curve448 -I../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I../deps/openssl/config -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2 -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/include -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto -I../deps/openssl/config/archs/darwin64-arm64-cc/asm_avx2/crypto/include/internal  -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -Wno-missing-field-initializers -fno-strict-aliasing -MMD -MF /Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/.deps//Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/methods.o.d.raw   -c
clang: error: no such file or directory: 'CXX=c++'
clang: error: no such file or directory: 'CXX=c++'
clang: error: no such file or directory: 'CXX=c++'
make[1]: *** [/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_msg.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/bio_ssl.o] Error 1
make[1]: *** [/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_lib.o] Error 1
clang: error: no such file or directory: 'CXX=c++'
clang: error: no such file or directory: 'CXX=c++'
make[1]: *** [/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/methods.o] Error 1
make[1]: *** [/Users/andy/.nvm/.cache/src/node-v15.2.1/files/out/Release/obj.target/openssl/deps/openssl/openssl/ssl/d1_srtp.o] Error 1
make: *** [node] Error 2
nvm: install v15.2.1 failed!
@aeharding
Copy link

Just installed for me on my m1 MacBook Air - nvm version 0.37.0 running nvm i v15

Try upgrading your version of nvm. I just dowloaded via the curl command.

Took a long time though - had to build node from source!

@kevcube
Copy link

kevcube commented Nov 17, 2020

I got a failure to install node v14 via NVM.

I assumed nvm wasn't working, and attempted installing node v15 via brew (on ARM) and it succeeded.

I'll try nvm again because I'd like older versions.

--update--
Tried nvm again, it's succeeding for v15, but not node v14.

I guess for now I'll live without old versions of node 😜

@ljharb
Copy link
Member

ljharb commented Nov 18, 2020

Old versions of node might simply not work on apple silicon machines.

Definitely don’t install nvm via homebrew; i don’t support that.

@sreuter
Copy link

sreuter commented Nov 18, 2020

Yeah, existing versions of node 14 simply don't compile.

I've opened a bug here: nodejs/node#36161

@ljharb
Copy link
Member

ljharb commented Nov 18, 2020

@andyaccelerate if you try with node 15 and the latest version of nvm, does everything work? If so, this should be closed.

@lukebettridge
Copy link

Installing older versions of Node wouldn't work for me either, tried v10 & v12 on the latest version of NVM. Took a long time but v15 installed successfully.

@AshCripps
Copy link

The support for apple silicon is only on master and possibly 15.x. older versions are expected to not work because they are missing the correct version of V8

@ljharb
Copy link
Member

ljharb commented Nov 18, 2020

What would be ideal, then, is for nvm to detect that you're on Apple Silicon, and trying to install a version that's not supported (< 15, at least), and fail with a helpful message. I'll leave this open to track that.

@ljharb ljharb added installing node Issues with installing node/io.js versions. OS: Mac OS pull request wanted This is a great way to contribute! Help us out :-D labels Nov 18, 2020
@ruffin--
Copy link

Quick warning that even once you've got the latest nvm up and running, you're going to be in a world of pain when you try to install dependencies. Pattern of...

node-pre-gyp WARN Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.4/fse-v1.2.4-node-v88-darwin-arm64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for fsevents@1.2.4 and node@15.2.1 (node-v88 ABI, unknown) (falling back to source compile with node-gyp) 

then lots of build errors before it gives up, at least for me.

So even though Node is limited to just building the latest, here's an OT heads up that lots of other stuff doesn't appear to be able to do even that. The Bleeding Edge Cuts (c) 1842.

@ljharb
Copy link
Member

ljharb commented Nov 18, 2020

Indeed, that will always be the case for compiled deps, but many dep graphs intentionally avoid having those :-)

@andyaccelerate
Copy link
Author

Thanks guys, when I first installed nvm I took the install script link from an article that I didn't realise was a bit old and installed v0.33 rather than the latest v0.37. Updating nvm fixed my issue with being able to install the latest version of node, but of course it looks like there is still the issue of installing older versions of node (which is not really the same problem as with my initial issue, but i'm sure I would of run into that one as well).

@bdruth
Copy link

bdruth commented Nov 19, 2020

Just fyi - if you set the Open using Rosetta option on Terminal.app or iTerm.app - you'll save yourself a lot of headache until more stuff works w/ aarch64 and the toolchain on the M1 macs. TBF, most if not all of this stuff already works on, e.g. Raspberry Pi or Amazon Graviton2 instances ... but, there's a lot of bad scripts that hard-code detections for macOS and do something differently ... it'll take awhile to get those sorted, I expect.

@olizh
Copy link

olizh commented Nov 20, 2020

Just fyi - if you set the Open using Rosetta option on Terminal.app or iTerm.app - you'll save yourself a lot of headache until more stuff works w/ aarch64 and the toolchain on the M1 macs. TBF, most if not all of this stuff already works on, e.g. Raspberry Pi or Amazon Graviton2 instances ... but, there's a lot of bad scripts that hard-code detections for macOS and do something differently ... it'll take awhile to get those sorted, I expect.

Wow! That's really really helpful! Saved me a lot of time and effort!

@PhoebePhilange
Copy link

using the latest version of nvm and i'm having this exact error as well on ubuntu though. Any suggestions on how to resolve it on linux?

@williamli
Copy link

williamli commented Nov 26, 2020

For anything under v15, you will need to install node using Rosetta 2.

You can do this by running the nvm installation commands inside the Rosetta 2 shell.

In Terminal, use

arch -x86_64 zsh

to start a shell under Rosetta 2.

Then you can run nvm install v12.

After this, you can use the installed executable without being in Rosetta 2 shell, i.e. you can use node 15 along with other node versions interchangeably.

image

This way you can use Rosetta on a need to use base and not need to run the whole terminal in Rosetta mode.

FYI @bdruth @olizh

Just fyi - if you set the Open using Rosetta option on Terminal.app or iTerm.app - you'll save yourself a lot of headache until more stuff works w/ aarch64 and the toolchain on the M1 macs. TBF, most if not all of this stuff already works on, e.g. Raspberry Pi or Amazon Graviton2 instances ... but, there's a lot of bad scripts that hard-code detections for macOS and do something differently ... it'll take awhile to get those sorted, I expect.

@ljharb
Copy link
Member

ljharb commented Nov 27, 2020

@williamli it would be great if you PRd a section into the readme for that :-)

@lovestulip
Copy link

lovestulip commented Dec 1, 2020

This worked for me. I was struggling big time. First generation Apple products are ..."fun".

@badalyan
Copy link

badalyan commented Dec 8, 2020

For anyone wondering how to do this....

  1. Right click the app (Terminal, iTerm, etc.)
  2. Tap "Get Info"
  3. Select "Open using Rosetta"
  4. Restart terminal and you're good to go!

Screenshots

Screen Shot 2020-12-07 at 11 07 04 PM

Screen Shot 2020-12-07 at 11 07 13 PM

@andreialecu
Copy link

It looks like running nvm install v15 on a Mac M1 CPU does build from source, but it still produces an x64 binary. This can be verified using node -p process.arch -> it prints x64 instead of arm64.

However, building node from source using homebrew creates a correct arm64 build.

I'm not sure if this should be reported as a separate issue. See nodejs/TSC#886 (comment)

@benwiggins
Copy link

benwiggins commented Dec 10, 2020

It looks like running nvm install v15 on a Mac M1 CPU does build from source, but it still produces an x64 binary. This can be verified using node -p process.arch -> it prints x64 instead of arm64.

This doesn't make sense, and is definitely not the case on my machine. Are you sure you're running the correct, nvm-compiled binary?

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
$ nvm install 15

Screen Shot 2020-12-10 at 11 58 02 am

@huan
Copy link

huan commented Dec 10, 2020

I have just got my M1 yesterday and it works like a charm as what @benwiggins said: nvm install 15 got a arm64 version!

@huming2207
Copy link

huming2207 commented Dec 10, 2020

I guess for those who got an x86 Node while you expect an arm64 Node, please check your Python. If Python is x86 then when Node is doing ./configure, it will generate an x86 Makefile.

i.e. You may need to install Homebrew in arm64 mode, then install Python via that, and make sure your PATH has /opt/homebrew/bin at the front (or uninstall the Python from x86 Homebrew or other previous 3rd-party, non-Apple Python installation)

@andreialecu
Copy link

andreialecu commented Dec 10, 2020

I just tried this again and it seems that node 15.4.0 is now out, and building it from source using nvm does produce an arm64 binary correctly. I checked python and it seems that it is an universal binary:

$ file `which python`
/usr/bin/python: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/usr/bin/python (for architecture x86_64):	Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture arm64e):	Mach-O 64-bit executable arm64e

Not sure if the new minor version fixed it or maybe I had an incompatible Python which somehow got updated by something I did.

Everything seems good now though.

Screenshot 2020-12-10 at 11 04 31

@williamli
Copy link

@williamli it would be great if you PRd a section into the readme for that :-)

@ljharb let me work on it over the weekend.

@hjoshi123
Copy link
Contributor

Is it okay if I start working on the README.md update for this? I got a new M1 recently and successfully installed v15 natively and v12 through rosetta.

@ljharb
Copy link
Member

ljharb commented Dec 22, 2020

@hjoshi123 thatd be great! It’ll be important to differentiate how M1 users can install both an arm and a rosetta version of node.

@maddybin

This comment has been minimized.

@victorsilva-i
Copy link

Installing v14 (nvm install v14) with "open using rosetta" marked and then opening again with it unmarked did the job for me. As I thought, you can use v14 without rosetta, only can't install it.

@DavidlblancoMaeztra
Copy link

solved >>> https://stackoverflow.com/questions/67254339/nvm-install-node-fails-to-install-on-macos-big-sur-m1-chip

@Prophe1

This comment has been minimized.

@levonter

This comment has been minimized.

@AlexeyJersey

This comment has been minimized.

@imaddi47
Copy link
Contributor

imaddi47 commented Nov 16, 2021

Well, I think just using arch -x86_64 zsh won't solve our problem. Let us understand this in this way...
-> If I am using shell script in which nvm will be used to install a specific version of node at the beginning and then execute further lined up commands. if I am using arch -x86_64 zsh, If will stop the execution of all other commands after arch -x86_64 zsh <~ this one until and unless we tap ctrl + c.

##Usecase Example: 1

We can clearly see here that this approach can't be used in automation in mac m1 as it will start a new instance of zsh with x86_64 architecture and won't follow our script to execute next lined up commands... Ultimately our script stuck just after arch x86_64 command

image

But if modify this as:

image
It is working fine because we temporarily modified "echo [can be other commands too]" for x86_64

##Usecase Example: 2
Using the same approach for installing node using nvm

Problem if we are not using arch -x86_64

image

Problem if we are using arch -x86_64

image

  • Here what we see is nvm is not accessible after adding arch -x86_64 nvm because when we use the inline arch change command, It is unaware of the RC file but it has a path of default locations like echo, bash, zsh, curl, and etc
  • So, we have to source RC file every time we install x86_64 based tools

Here is my solution:

Prerequisite:

~> install rosetta 2 using terminal otherwise arch -x86_64 won't work

$ /usr/sbin/softwareupdate --install-rosetta --agree-to-license

Solution:

#!/bin/zsh
# Just to get environment path for nvm
source ~/.zshrc

arch -x86_64 zsh -c ". ~/.zshrc && nvm install v12.13.0"
arch -x86_64 zsh -c ". ~/.zshrc && nvm use v12.13.0"
arch -x86_64 zsh -c ". ~/.zshrc && nvm alias default v12.13.0"

image

Since arch x86_64 create temporary instance of x86_64 architecture to execute , we are creating temporary zsh shell with x86_64 architecture to execute desired command. But again, since it is an inline new instance and it is unaware of the RC file. That's why we are sourcing RC file every time we want to execute third-party tools with their path in RC files.

Code breakdown

  • Remember we used #!bin/zsh as our shell, so we intended to perform our operation in zsh with .zshrc file
  • we will break our command in different parts 1~> arch -x86_64 2~> zsh -c 3~>". ~/.zshrc && 4~>nvm install v12.13.0"
  • arch -x86_64 : initializing new shell instance with x86_64 architecture
  • zsh -c : linking that newly created shell with "zsh" and "-c" is for followed up command
  • ". ~/.zshrc && : sourcing RC file for "zsh" that is ".zshrc" to load all paths of third-party tools which also included "nvm"
  • nvm install v12.13.0" : finally we are running our desired command on x86_64 architecture

That's all!!! Hope this will help a lot to all of those automation developers who do not intended to use GUI for automating Mac M1

@ljharb
Copy link
Member

ljharb commented Nov 16, 2021

@imaddi47 what do you think about a PR to automate those steps in nvm itself?

@imaddi47
Copy link
Contributor

@imaddi47 what do you think about a PR to automate those steps in nvm itself?

Sure! I would love to.

@RichardWaters90
Copy link

quit the terminal
right click - go to "get info"
select "open in rosetta"
this should allow nvm to install older versions

@SSylvain1989
Copy link

quit the terminal right click - go to "get info" select "open in rosetta" this should allow nvm to install older versions

thanks for the help , i have this issue :

ERROR: Did not find a new enough assembler, install one or build with
       --openssl-no-asm.
       Please refer to BUILDING.md

anyone know how to fix that ? on MBA M1

@thisiseesmaeel
Copy link

I get the following error, running on a m1 chip macbook. Any idea how to deal with this one, worth to note that I have gone through all of the above solutions.

> Could not find node-14.16.0-darwin-arm64.tar.gz (org.nodejs:node:14.16.0).
        Searched in the following locations:
            https://nodejs.org/dist/v14.16.0/node-v14.16.0-darwin-arm64.tar.gz

@imaddi47
Copy link
Contributor

imaddi47 commented Feb 2, 2022

I get the following error, running on a m1 chip macbook. Any idea how to deal with this one, worth to note that I have gone through all of the above solutions.

> Could not find node-14.16.0-darwin-arm64.tar.gz (org.nodejs:node:14.16.0).
        Searched in the following locations:
            https://nodejs.org/dist/v14.16.0/node-v14.16.0-darwin-arm64.tar.gz

Have you updated nvm version to 0.39.1 because it is tested after merging this PR
image

@TimJi

This comment was marked as outdated.

@ljharb

This comment was marked as resolved.

@luyaozhi
Copy link

(
cd "$NVM_DIR"
git fetch --tags origin
git checkout git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)
) && . "$NVM_DIR/nvm.sh"

@luyaozhi

This comment was marked as spam.

@mr250792
Copy link

For anyone wondering how to do this....

  1. Right click the app (Terminal, iTerm, etc.)
  2. Tap "Get Info"
  3. Select "Open using Rosetta"
  4. Restart terminal and you're good to go!

Screenshots

Screen Shot 2020-12-07 at 11 07 04 PM Screen Shot 2020-12-07 at 11 07 13 PM

It work well for me

thx ~

tips: need to restart iTerm app

In mac M2 chip

Its Terminal instead of iTerm and can be found in the Application/Utilities folder

@ljharb
Copy link
Member

ljharb commented May 23, 2023

Not just with an M2; on all Macs. iTerm is just a commonly used userland shell.

@Sinpo96
Copy link

Sinpo96 commented Dec 25, 2023

For anyone wondering how to do this....

  1. Right click the app (Terminal, iTerm, etc.)
  2. Tap "Get Info"
  3. Select "Open using Rosetta"
  4. Restart terminal and you're good to go!

Screenshots

Screen Shot 2020-12-07 at 11 07 04 PM Screen Shot 2020-12-07 at 11 07 13 PM

It work well for me
thx ~
tips: need to restart iTerm app

In mac M2 chip

Its Terminal instead of iTerm and can be found in the Application/Utilities folder

Thanks! It works for me,I'm M3

@kerberw
Copy link

kerberw commented Jan 2, 2024

I think it is time to update the docs on Rosetta now.
This has been in for a good while: #2657

@ljharb
Copy link
Member

ljharb commented Jan 6, 2024

@kerberw PRs welcome :-)

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 pull request wanted This is a great way to contribute! Help us out :-D
Projects
None yet
Development

Successfully merging a pull request may close this issue.