Install Node on M1 Mac - node.js

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

Related

Why install node js version 8.xx but still show version v6.3.1?

My server is centos 7
I was install node js 8.x with this command line
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
and
sudo yum -y install nodejs
When finished i will check version by node -v but still show v6.3.1
How can i do ?
I would recommend you to use NVM (Node Version Manager) to manage your node versions. It's very useful and it's a great tool to manage your node versions.
To install NVM, run this script on your console:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Then, to download the latest release of node the following two commands:
nvm install node
nvm use node
If you want to install a specific version of node, you can simply run:
nvm install v8.9.0
nvm use v8.9.0
I hope this helped, if you're still having trouble please let me know.

How to downgrade Node version

I want to downgrade my Node version from the latest to v6.10.3.
But nothing worked so far. Tried NVM and it gives an error as well by saying make command is not found. How can I downgrade Node?
Warning:
This answer does not support Windows OS
You can use n for node's version management. There is a simple intro for n.
$ npm install -g n
$ n 6.10.3
this is very easy to use.
then you can show your node version:
$ node -v
v6.10.3
For windows nvm is a well-received tool.
For windows:
Steps
Go to Control panel> program and features>Node.js then uninstall
Go to website: https://nodejs.org/en/ and download the version and install.
Determining your Node version
node -v // or node --version
npm -v // npm version or long npm --version
Ensure that you have n installed
sudo npm install -g n // -g for global installation
Upgrading to the latest stable version
sudo n stable
Changing to a specific version
sudo n 10.16.0
Answer inspired by this article.
In Mac there is a fast method with brew:
brew search node
You see some version, for example: node#10 node#12 ... Then
brew unlink node
And now select a before version for example node#12
brew link --overwrite --force node#12
Ready, you have downgraded you node version.
This may be due to version incompatibility between your code and the version you have installed.
In my case I was using v8.12.0 for development (locally) and installed latest version v13.7.0 on the server.
So using nvm I switched the node version to v8.12.0 with the below command:
> nvm install 8.12.0 // to install the version I wanted
> nvm use 8.12.0 // use the installed version
NOTE: You need to install nvm on your system to use nvm.
You should try this solution before trying solutions like installing build-essentials or uninstalling the current node version because you could switch between versions easily than reverting all the installations/uninstallations that you've done.
For windows 10,
Uninstalling the node from the "Add or remove programs"
Installing the required version from https://nodejs.org/en/
worked for me.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
sudo npm install -g n
sudo n 10.15
npm install
npm audit fix
npm start
If you're on Windows I suggest manually uninstalling node and installing chocolatey to handle your node installation. choco is a great CLI for provisioning a ton of popular software.
Then you can just do,
choco install nodejs --version $VersionNumber
and if you already have it installed via chocolatey you can do,
choco uninstall nodejs
choco install nodejs --version $VersionNumber
For example,
choco uninstall nodejs
choco install nodejs --version 12.9.1
If you are on macOS and are not using NVM, the simplest way is to run the installer that comes from node.js web site. It it clever enough to manage substitution of your current installation with the new one, even if it is an older one. At least this worked for me.
Try using the following commands
//For make issues
sudo apt-get install build-essential
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
//To uninstall a node version
nvm uninstall <current version>
nvm install 6.10.3
nvm use 6.10.3
//check with
node -v
Steps to downgrade to node8
brew install node#8
brew link node#8 --force
if warning remove the folder and files as indicated in the warning then again the command :
brew link node#8 --force
For windows users, you guys can downgrade using following commands.
npm uninstall -g node
npm install -g node#version
#version is your specified version, example : 12.22.3(little old)
Can find node releases here https://nodejs.org/en/download/releases/
I have used brew in mac to downgrade the node
follow the steps you will have the result:
brew search node (here you can see the version eg: node#10, node#12, node#14)
brew unlink node
brew install < node version > (eg: node#12)
brew link --overwrite node#12
If you are using nvm, following are the ways -
1. nvm install node_version
2. nvm use --delete-prefix node_version
For more insights, see this image -
Ubuntu:
nvm list
nvm use <version>
nvm list // Shows all the versions on your machine. Of course have your version installed.
nvm use // Use this version
it seems to be a compatibility issue, run
sudo n 14
then npm install or yarn install again. It will work
In case of windows, one of the options you have is to uninstall current version of Node. Then, go to the node website and download the desired version and install this last one instead.
I had to downgrade node to v10.16.0
sudo n 10.16.0
nvm use v10.16.0
this solved the problem for me
WINDOWS: Best way that you can do it and to not lose time.
Go to control panel
Uninstall Program
Uninstall node
Then go and find the version that you want to install, install it from the beginning.
Link with node versions: https://nodejs.org/uk/blog/release/
Here is a simple solution
Go to this link and download & install the suitable nvm setup on your computer
https://github.com/coreybutler/nvm-windows
Type nvm list to get list of installed node versions
Type nvm install <node-version>
Type nvm use <version>
here we go you got node version you want.
Browse here to find node versions => https://nodejs.org/en/download/releases/
The Node.js team suggests to use the following Node.js version managers to switch between different versions of Node:
OSX or Linux:
nvm
n
Windows:
nodist
nvm-windows
I personally made good experiences using "nvm-windows" on Windows 11.
I would recommend using NVS (Node Version Switcher).
You can see the source here and all you need is a package manager. Like Chocolatey or Homebrew.
Install it
choco install nvs
Add a version:
nvs add v16
Switch to any version you installed
nvs use v16
At the end if you "run node -v" you'll get the current you've switched.

Can somebody please tell me if I am using the wrong node js version?

I have been trying to update nodejs for a long time now. When I run node -v, it tells me I am using: v0.10.40. But when I look at nodejs.org it says the v7.4.0?
I have cleaned the npm cache and done a reinstall with sudo n stable but still v0.10.40, and the last time that I updated npm it prompted me that my node version is too old and outdated.
What am I doing wrong. And can somebody tell me if v0.10.40 is the current or an outdated version?
You likely have two versions of node installed and in your path. If you are on OSX or linux, run which node (if on Windows, you may npm i -g #raider/which, and then run which node). This should give you the location of the old version of node.
Then run mv path/to/old/node path/to/old/node.bak, replacing with the actual path, and rerun node --version to see if it picks up the right version now.
UPDATE: If you are on Ubuntu or another Debian based Linux, you should install the latest with the following commands:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
UPDATE: If you are using nvm, run nvm install node followed by nvm use node in a new terminal to get the latest that nvm supports.

How to upgrade Node js version to 0.12.4 on Ubuntu

I want to upgrade Node JS version on Ubuntu.
I tried many commands but its version is still the older i.e v0.10.37.
I tried:
sudo npm install -g n
sudo n install 0.12.4
sudo n use 0.12.4
Also tried with nvm but non of them works for me. How can I upgrade Node Js version to 0.12.4?
Use npm in order to upgrade node
First Clean the cache and try
sudo npm cache clean -f
sudo npm install -g n
sudo n 0.12.4
Then create a symbolic link(It is needed only sometimes, first try with these three commands. If it doesnot work add this.)
It will be updated to 0.12.4 Version.
It could be enough just to install n module:
sudo npm install -g n
and then simply run:
sudo n 0.12.4
The trick is that it may not be updated in your current terminal session. So you can simply open one more tab in your terminal or just another terminal and check your nodejs version by:
node --version
That's it, output will be v0.12.4
The official doc from nodejs repository points to this : https://nodesource.com/blog/nodejs-v012-iojs-and-the-nodesource-linux-repositories#installing-node-js-v0-12
Just follow it and you'll have the 0.12.4.
Try running this in terminal:
nvm install 5.10.1
nvm use 5.10.1
The version may be change.
Cheers!
Execute following comand to upgrade nodejs to 0.12.x
Note the new setup script name for Node.js v0.12
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
Then install with:
sudo apt-get install -y nodejs
Just ignore warning. By executing both commands it worked for me on Ubuntu 14.04
On Ubuntu 16.04
There is no special or dedicated comand to upgrade node version. The correct way to install or upgrade node on ubuntu is:
1) download the distribution you wish from nodejs official site, move the file into a known path
2) open a terminal and run: >sudo tar -C /usr/local --strip-components 1 -xzf "known path/name_of_the_distribution_file...gz
3) test if everything is ok: open a new terminal and run node --version. It should echo the version you downloaded and installed/upgraded.

Installing nvm on Ubuntu 14.04

I'm trying to install nvm on Ubuntu 14.04 but it doesn't seem to use the version I specify. I installed following the tutorial here https://github.com/creationix/nvm and I've also tried the one here https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps.
There are 2 node installations on my system already.
which node # => /usr/local/bin/node
node --version # => v0.11.13-pre
which nodejs # => /usr/bin/nodejs
nodejs --version # => v0.10.26
When I install nvm using the curl one liner they give you, and then use
nvm install 0.10.32
It creates an empty folder inside .nvm/v0.10.32 and .nvm/current symlinks to it.
In addition the bin folder is also empty. This problem occurs if I install other
versions of node. I suppose I could just clone a version of node into the folder
its supposed to go in but idk if that's all I have to do. In addition, I'm not sure
I know how to make my system use the nvm current (symlink from /usr/local/bin/node to .nvm/current ?) Without doing anything myself and only following the tutorial, node --version and nodejs --version never uses the version I specify with.
nvm use 0.10.32
Here is my personal guide how to install nvm (node version manager).
reference: https://github.com/creationix/nvm
1.) Install nvm (NOTE: There might be new versions in their website.)
curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash
2.) Close the current terminal and use a new terminal then try nvm again.
3.) Install current node.js version by using:
nvm install node_version
ex: nvm install 0.10.32
4.) to check the nodejs version--> nvm list
5.) Setup a default node version in nvm so that everytime you restart
the system it loads a default node version:
to get help: nvm -h
to get list of install node.js versions: nvm ls
to set a default alias: nvm alias default node_version
6.) Uninstall a specific node.js version:
nvm uninstall node_version
I understand that my answer may be outdated, but there was a very nice thesis in the ticket #809, that using
$ npm install -g nvm
is wrong. To fix, you want to do
$ npm uninstall -g nvm
$ apt install curl
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
$ source ~/.bashrc
$ nvm install 5.1
$ nvm use 5.1
instead (given that curl hasn't yet been installed on that machine).
I just removed all of the offending node installations until my system used a version that was 0.10.* . It appears I tried to install node before or another program installed it.

Resources