nvm install node fails to install on macOS Big Sur M1 Chip - node.js

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++'

If you have installed nvm using homebrew and are trying to install the node using command nvm install <some_version>, you will face errors on apple silicon machines (ARM) for versions lower than 15. Node versions older than 15 do not work on apple silicon machines (ARM) because ARM architecture is not supported.
For anything under v15, you will need to install node using Rosetta 2.
How to open terminal in Rosetta2 mode: Go to Application -> Right click on terminal app -> Get Info -> Select "Open using Rosetta" -> Restart Terminal
In Terminal, write -> arch -x86_64 zsh
Now you will able to install any version of node (even multiple versions)

it wasn't an issue while i was trying to install node 12.X.X but below that it was a big pain so i followed below steps and it worked for me
Uninstalled nvm if it’s already installed using Homebrew.
brew uninstall nvm
brew cleanup
Install Rosetta
softwareupdate --install-rosetta
Make terminal/iTerm2 to open in Rosetta mode
got to Application (-> utilities) -> right click on terminal app -> get Info -> Select "Open using Rosetta" -> Restart Terminal
In Terminal run a command
arch -x86_64 zsh
Make sure machine has .zshrc file if not just create one
cd ~
touch .zshrc
Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
And it should add the below piece of code to .zshrc
Restart the terminal and check if nvm is installed successfully by running
nvm -v
Then install Node with nvm as usual
nvm install 10

The best instructions are on nvm's own Readme's FAQ on Macs with M1 processors:
https://github.com/nvm-sh/nvm#macos-troubleshooting

I found a solution that really worked well here, am not going to write the entire steps please follow this link [Rosetta Terminal]

I did the following:
Run software update:
softwareupdate --install-rosetta --agree-to-license
Error in Rosetta Updater, but you can:
grep RosettaUpdateAuto.pkg /var/log/install.log
and just:
open /path/to/RosettaUpdateAuto.pkg
After that, right-click your terminal icon in dock > Open > Options > Show in Finder.
Then, right-click > Get Info.
Then, check 'Open using Rosetta'
In the terminal you can check you are using rosetta with:
arch
Then just:
nvm install v6.9.1 # for example

Install nvm version > 0.3.7 and install node version >= 16.0

Use the following command for successful install:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
before the above command, please be sure to have .zshrc file in the root of your current username folder (~/).

Related

Failed to "nvm install 8.0.0"

My goal is to install node version 8 so I can run Gulp on a project.
I'm working on an old project that has been neglected and passed downed to me by another developer. I'm told I can work with Gulp by installing Node Version 8 and declaring the node version in my package.json file.
But whenever I try to run nvm install 8I receive the error error: "unsupported ARM architecture"
My system is MacOS Big Sur M1 Chip
I am not too sure what I'm supposed to do here. Please help!
Solution
The solution was to change the architecture of my shell from arm64 to x86.
Macs with M1 chip
January 2021: there are no pre-compiled NodeJS binaries for versions prior to 15.x for Apple's new M1 chip (arm64 architecture).
Some issues you may encounter:
using nvm to install, say, v14.15.4:
the C code compiles successfully
but crashes with an out of memory error when used
increasing the memory available to node still produces the out of memory errors: $ NODE_OPTIONS="--max-old-space-size=4096" ./node_modules/.bin/your_node_package
when using nvm to install some versions, the compilation fails
One solution to this issue is to change the architecture of your shell from arm64 to x86.
Let's assume that:
you already have versions 12.20.1 and 14.15.4 installed using nvm
the current version in use is 14.15.4
you are using the zsh shell
you have Rosetta 2 installed (macOS prompts you to install Rosetta 2 the first time you open a Intel-only non-command-line application, or you may install Rosetta 2 from the command line with softwareupdate --install-rosetta)
//# 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)
source: https://github.com/nvm-sh/nvm
Find UR iTerm (or any other termial ur using)
Double-click =>【get info】
In General Panel:
✅ Open using Rosetta (selected this item)
Back to termial and continue use nvm install 8

NVM on WSL2: cannot install Node, version not found

I installed WSL from the Microsoft Store onto Windows 10. I was able to succesfully install NVM onto this using the curl command as documented on https://github.com/nvm-sh/nvm
NVM installs, I can run commands and check the version.
However when I try to install node, either a specific version like nvm install 12.18.1 or nvm install or nvm install --lts I get a message that the version is not found
me:~$ nvm install 12.18.1
Version '12.18.1' not found - try `nvm ls-remote` to browse available versions.
or
me:~$ nvm install --lts
Installing latest LTS version.
Version '' (with LTS filter) not found - try `nvm ls-remote --lts` to browse available versions.
If I try to run nvm ls-remote, after several seconds I get N/A
I have installed this before on MacOS and on a different non-work Windows 10 box and have not seen this behavior before. It's like it is not hitting the nodejs server.
Thoughts?
I had experienced the same issue on a work laptop running WSL2. It was caused by a proxy/firewall solution (ZScaler) installed on the PC which was blocking connections to nodejs.org. To test is this is the issue you can run the command below to see if it runs successfully
curl -I --compressed -v https://nodejs.org/dist/
The solution for me was to run a VPN on my PC which would bypass that restrictions of the corporate proxy and allow me to download the node versions required. Alternatively you can work with your IT department to have nodejs.org unblocked.

Install Node on M1 Mac

Kind of a noob here on questions about binaries, processors and how that all works together:
I have a new Mac with an M1 chip, and want to install Node. I'm used to do this with Homebrew. Now, if I install Homebrew, I'm strongly recommended to use Rosetta, so I did. Next step: installing Node. So instead of brew install node I do arch -x86_64 brew install node.
This works fine, only I'm wondering, am I now using node in a sub-optimal way? Is Node also using Rosetta, instead of directly running on the M1 chip?
Depending on your project dependencies, you might find it necessary to run node on an x86 architecture as it may get you past frustrating errors on older versions of node. If like me you had already installed node in your attempts here, you can use the following to help get you sorted (assuming you have already installed NVM):
$ nvm uninstall 14
$ arch -x86_64 zsh
$ nvm install 14
$ nvm alias default 14
Consider replacing 14 above with whichever node version you are attempting to run under.
After installing, you can run node followed process.arch to confirm that node is running in x64 mode:
$ node
> process.arch
'x64'
I just got my M1 Mac mini. I did add an alias since I use oh-my-zsh to my ~/.zshrc for alias brew=arch -x86_64 brew so I don't have to keep typing all that. I brew install nvm then nvm ls-remote and installed v15.5.0. It gets built DV8_TARGET_ARCH_ARM64.
Hope that helps. I also pulled the insiders VSCode for ARM64. Loads in a second.
> node -p "process.arch"
arm64
Don't forget you need xcode-select --install command line tools (~450MB).
From node v16.x:
https://doesitarm.com/app/nodejs/
PS: node v16 has problems with serverless-offline. I managed to solve it using node v15.4.0
From node v15.x:
sudo xcode-select --install
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install v15
node --version
As Node v16 natively supports Apple Silicon, brew install node or nvm install 16 would work on the Apple M1 laptops.
Here is my current build.
$ nvm --version
0.39.0
$ node --version
v16.13.1
$ node -p "process.arch"
arm64
To install Node 15.6.0 or higher:
Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Install NodeJS
nvm install v15
To verify if both nvm and NodeJS were installed successfully, run:
node -v
npm -v
You can find more information here
Nvm install 14.15.3 (current LTS) wasn't successful for me in any of the attempts (with brew arch -x86_64 prefix as well). But, I was able to:
install nvm from github (with putting the "export" string to ~/.zhrc and executing it)
nvm install 15
Note: This VSCode version works for me as well: https://code.visualstudio.com/docs/?dv=osx&build=insiders
Open Terminal Using Rosseta 2 if you haven't installed rosseta2 yet
Just Check out my blog to set up it
https://siddhantjohari.medium.com/setting-up-react-native-in-mac-m1-aaf18c37fc34
Install Homebrew using this command.
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Now hit this command to install nodejs or anything you want
arch -x86_64 brew install <package>
Thank you.
you can install node using n, please follow the link.
n --arch arm64 16

I just installed Nodejs 14.4 from the site, but when I check the version in Command Prompt it shows version 8.10

title says it all. I have been using nodejs with npm for while now and it has been working fine, but I went to check the version and noticed it was an older one. Nodejs - version 8.10.0 and npm - version 3.5.2. I know there are more recent versions of each and like I said I went to download the new version of Nodejs and I got it. I have the path set up to its location in my Environment Variable. I'm not sure what I'm missing. Would love any help.
Edit: Forgot to mention on my original post that I am on Windows.
Edit2: So I was looking at it more and I am using the Ubuntu Bash Shell on muy windows computer. Whenever I check the version in the normal Windows Command Prompt it displays the right version, but when I check it in the Bash shell it is wrong. Any ideas why this happens?
The Node Version Manager. You can find it at https://github.com/coreybutler/nvm-windows
It allows you to easily install and manage multiple versions of node. Here's a snippet from the help:
Usage:
nvm install <version> Download and install a <version>
nvm use <version> Modify PATH to use <version>
nvm ls List versions (installed versions)
install and Usage:
nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
and then
nvm use 6.14.4
So, I was able to solve my own issue
These two links were very important for solving my issue:
E: Unable to locate package npm
https://learn.microsoft.com/en-us/windows/wsl/install-win10#update-to-wsl-2
So basically after uninstalling nodejs I went and tried uninstalling and reinstalling my Ubuntu Bash shell. Once I had the Bash shell set up again I tried running the commands listed in the stackoverflow post I have listed above. (note: When you run the curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - line you need to adjust the "setup" version to 14.x) When I ran all the commands I was able to get my npm version up-to-date, but my nodejs was still being stuck at version 10.x. I tried running the install again on nodejs and thats when I noticed an error reading gpg: can't connect to the agent: IPC connect call failed I did some research on this error and foudn out my WSL1 would not allow it to update to the most recent version. Thats how I found my way to the Microsoft page that led to me needing to update my version of Windows to 1909 and then installing WSL2 through Power Shell. Everything is now up-to-date and working!
You could Uninstall both versions and reinstall the newer version. That should do it
Or better still download the NVM and follow the instructions from here
https://blog.logrocket.com/switching-between-node-versions-during-development/

Unable to link/run Node.js v6 in Homebrew

I'm trying to specifically install Node.js v6, which is proving confusingly difficult.
On a new MacBook running Sierra, I've run:
brew install node#6
This gave me:
Please note by default only English locale support is provided. If you need
full locale support you should either rebuild with full icu:
`brew reinstall node --with-full-icu`
or add full icu data at runtime following:
https://github.com/nodejs/node/wiki/Intl#using-and-customizing-the-small-icu-build
This formula is keg-only, which means it was not symlinked into /usr/local.
This is an alternate version of another formula.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/node#6/bin:$PATH"' >> ~/.zshrc
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/node#6/lib
CPPFLAGS: -I/usr/local/opt/node#6/include
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node#6/6.9.5: 3,891 files, 41.3M
If I run which node, I get node not found. If I run brew link node, I get Error: No such keg: /usr/local/Cellar/node. I also ran sudo chown -R $USER /usr/local.
How can I "link" Node.js v6 so that other software can find it? Do I run echo 'export PATH="/usr/local/opt/node#6/bin:$PATH"' >> ~/.zshrc? I don't want to run anything I'm not sure of.
Don't use Homebrew to install node.
I like the Node Version Manager (NVM), and there is n (as mentioned by #ntalbs in the comments). These are better options on a Mac for node, to avoid certain. issues. later.
Note, you can install nvm and n via Homebrew. (brew install nvm or brew install n).

Resources