nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
77.21k stars 7.76k forks source link

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

Closed andyaccelerate closed 3 years ago

andyaccelerate commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

I've opened a bug here: https://github.com/nodejs/node/issues/36161

ljharb commented 3 years ago

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

lukebettridge commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

ruffin-- commented 3 years ago

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 commented 3 years ago

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

andyaccelerate commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

lovestulip commented 3 years ago

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

badalyan commented 3 years ago

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 commented 3 years ago

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 https://github.com/nodejs/TSC/issues/886#issuecomment-741682896

benwiggins commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

Suhail commented 3 years ago

In zsh, I did:

Downloading and installing node v15.5.0...
Downloading https://nodejs.org/dist/v15.5.0/node-v15.5.0-darwin-arm64.tar.xz...

curl: (22) The requested URL returned error: 404
Binary download from https://nodejs.org/dist/v15.5.0/node-v15.5.0-darwin-arm64.tar.xz failed, trying source.
grep: /Users/suhail/.nvm/.cache/bin/node-v15.5.0-darwin-arm64/node-v15.5.0-darwin-arm64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Detected that you have 8 CPU core(s)
Running with 7 threads to speed up the build
Clang v3.5+ detected! CC or CXX not specified, will use Clang as C/C++ compiler!
Downloading https://nodejs.org/dist/v15.5.0/node-v15.5.0.tar.xz...

I noticed in bash it would download x64

I still got x64 vs arm64 :(

jhildenbiddle commented 3 years ago

FWIW:

On a new MacBook Air M1 with macOS 11.1 using the default zsh shell, running the curl installation produced an arm64 version of node v15.5.0. 🎉

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
> node -v
v15.5.0
> node

Welcome to Node.js v15.5.0.
Type ".help" for more information.
> process.arch
'arm64'
dekz commented 3 years ago

For those who got stuck continually building x86_64, make sure your shell itself is the new system defaults. I had previously used the migration assistant and had some left over builds of zsh and bash which were running in rosetta mode in /usr/local/bin.

Before (/usr/local/bin/zsh)

~ λ uname -m
x86_64
~ λ sysctl sysctl.proc_translated
sysctl.proc_translated: 1

After /bin/zsh

~ λ uname -m
arm64
~ λ sysctl sysctl.proc_translated
sysctl.proc_translated: 0

Also make sure that the found python isn't an x86_64 build either

~ λ file $(which python3)
/usr/bin/python3: 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/python3 (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python3 (for architecture arm64e): Mach-O 64-bit executable arm64e
sc0tt5 commented 3 years ago

@williamli 's solution worked for me. Thanks!

I'm running an Angular 10 project which requires node 10.13.x/12.11.x. I'm using node 12 via nvm. I came looking for a solution after npm install was running extremely slow. What would normally take my MacBook Pro i7 around a minute, the M1 was was taking more than an hour. Same for ng serve, it was taking forever.

Sorry to rehash what has already been said, but in case it helps anyone this is what I did.

First, confirm the node version and that it's running on arm64:

~ node -v
v12.11.1
~ node -p process.arch
arm64

Next, uninstall the arm64 version of node. Using nvm, we need to switch to a different version before we can uninstall:

~ nvm use 10
Now using node v10.11.0 (npm v6.4.1)
~ nvm uninstall 12.11.1
Uninstalled node v12.11.1
~ nvm ls
v10.11.0
v15.5.0

Next, switch to x64 and reinstall node 12:

~ arch -x86_64 zsh
~ node -p process.arch
x64
~ nvm install 12.11
Now using node v12.11.1 (npm v6.11.3)
originalix commented 3 years ago

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.

thx , that's helpful for me . Although my m1 macbook pro didn't delivery

yokiizx commented 3 years ago

node -p process.arch

how to reback arm64?

davy-gan commented 3 years ago

2407 我同样遇到这个问题,该怎么解决额

mcalthrop commented 3 years ago

@williamli 's solution worked for me. Thanks!

I'm running an Angular 10 project which requires node 10.13.x/12.11.x. I'm using node 12 via nvm. I came looking for a solution after npm install was running extremely slow. What would normally take my MacBook Pro i7 around a minute, the M1 was was taking more than an hour. Same for ng serve, it was taking forever.

Sorry to rehash what has already been said, but in case it helps anyone this is what I did.

First, confirm the node version and that it's running on arm64:

~ node -v
v12.11.1
~ node -p process.arch
arm64

Next, uninstall the arm64 version of node. Using nvm, we need to switch to a different version before we can uninstall:

~ nvm use 10
Now using node v10.11.0 (npm v6.4.1)
~ nvm uninstall 12.11.1
Uninstalled node v12.11.1
~ nvm ls
v10.11.0
v15.5.0

Next, switch to x64 and reinstall node 12:

~ arch -x86_64 zsh
~ node -p process.arch
x64
~ nvm install 12.11
Now using node v12.11.1 (npm v6.11.3)

Brilliant, thanks @williamli and @sc0tt5!

Those instructions almost worked for me, so I've written a gist with the instructions that did work for me, using your comment as a basis: https://gist.github.com/mcalthrop/4618bcaa1b3cd3fe6bba1a9b8bb71b1c I linked back to your GH comment above. 😄

ljharb commented 3 years ago

@mcalthrop would you be interested in PRring that content into the readme?

mcalthrop-lego commented 3 years ago

@mcalthrop would you be interested in PRring that content into the readme?

Yes, definitely. I'll do it as soon as I can – in the next few days.

mcalthrop commented 3 years ago

@mcalthrop would you be interested in PRring that content into the readme?

@ljharb Was able to get to it earlier than I expected: #2416

aldiarian commented 3 years ago

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

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

If you are in a M1 apple silicon machine and want to change to an old node version just follow this link https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g

MSK0379 commented 3 years ago

First generation Apple products are ..."fun

First generation Apple products are ..."fun~

realmiya commented 3 years ago

just use homebrew to upgrade node, https://www.jianshu.com/p/7c961fbd2d71 see this article, everything can be resolved

ljharb commented 3 years ago

@realmiya absolutely never use homebrew to install node.

thomaskanzig commented 3 years ago

node -p process.arch

how to reback arm64?

Use this command to go back:

exit
NerdyDeedsLLC commented 3 years ago

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

Gods. Bless. You. Sir.

sidjoshi001 commented 3 years ago

https://github.com/nvm-sh/nvm#macos-troubleshooting

I think they have already a solution...😎

Using Rosetta 2

Check what version you're running:

$ node --version v14.15.4

Check architecture of the node binary:

$ node -p process.arch arm64

This confirms that the arch is for the M1 chip, which is causing the problems.

So we need to uninstall it.

We can't uninstall the version we are currently using, so switch to another version:

$ nvm install v12.20.1

Now uninstall the version we want to replace:

$ nvm uninstall v14.15.4

Launch a new zsh process under the 64-bit X86 architecture:

$ arch -x86_64 zsh

Install node using nvm. This should download the precompiled x64 binary:

$ nvm install v14.15.4

Now check that the architecture is correct:

$ node -p process.arch x64

It is now safe to return to the arm64 zsh process:

$ exit

We're back to a native shell:

$ arch arm64

And the new version is now available to use:

$ nvm use v14.15.4 Now using node v14.15.4 (npm v6.14.10)

🎉

NerdyDeedsLLC commented 3 years ago

I think they have already a solution...😎

Nicely-spotted @sidjoshi001 ! Good looking out, following back to this thread, too! It appears the rumors circulating about you (I'm referring, of course, to those surrounding your pending candidate for the role of "da man") were well-founded after all. Huh. Well, you got my vote.

mcalthrop commented 3 years ago

https://github.com/nvm-sh/nvm#macos-troubleshooting

I think they have already a solution...😎

https://github.com/nvm-sh/nvm/issues/2350#issuecomment-764929504

mayouzi commented 3 years ago

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

maddybin commented 3 years ago

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!

This Works

victorsilva-i commented 3 years ago

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 commented 3 years ago

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