Update system version of node with nvm - node.js

I usually do not have any issues with nvm, but a React Native / Xcode project is failing to build because it's trying to use Node v4.4.3.
My nvm ls looks like this:
v5.11.0
v5.11.1
v6.1.0
v6.9.5
v6.11.5
-> v8.7.0
v10.1.0
system
When I type nvm use system and node -v it prints 4.4.3, so I suppose that's where Xcode is getting 4.4.3 from.
But when I type nvm alias system 8.7.0 (attempting to alias the system to 8.7.0), it prints system -> 8.7.0 (-> v8.7.0) and node -v still returns 4.4.3.
I also tried nvm install 8.7.0 --reinstall-packages-from=node, but that didn't really seem to do anything to help the cause.
I probably had node installed with brew at one point, but believe I've installed it because brew node -v returns Error: Unknown command: node Error: Kernel.exit.
Wondering if anyone can point me in the correct direction!

. ~/.nvm/nvm.sh at the top of the shell script in Build Phases did the trick.

Try this answer:
https://stackoverflow.com/a/11298299/8723007
I also installed node with brew at some point which I just forgot about it because I also use nvm.
:facepalm:
Try $ brew upgrade node in Terminal and if that doesn't work trying installing node with homebrew anyway. You should get the system version to be the most up to date. As of rn that's version 11.

Related

node version manager not changing the Node Version in Ubuntu. Stuck on system node version. How to change node version using nvm?

I am trying to do
npm install wrtc
with node version 16.14.0
but that's not getting done. It's giving
npm error code 1
So I was trying to change node version to previous lts which was 14.19.0 but it's not getting changed
I did...
node -v
nvm list
nvm use 14.19.0 => output - ***Now using node v14.19.0 (npm v8.5.3)***
node -v (version not changed... Still 16.14.0
nvm list - shows the arrow mark '->' still on system
Are you following these steps?
Please make sure that your npm version is correctly installed according to your node version.

npm is not compatible with Node.js

I had node installed in my machine and everything was working fine. During an online course made in 2019, the instructor was using an earlier version of npm (v5.5.1) and advised everyone to use the same version with him for follow up reasons. So I downgraded to v5.5.1 but now I keep getting one same error (incompatibility) for almost all commands. I read some solutions to similar problems here and even tried extra steps but the problem still persists.
I uninstalled node from my system, restarted the system and reinstalled node but the version of npm still remained v5.5.1.
I tried to uninstall npm from the command line npm uninstall -g npm but it threw incompatibility error.
I searched the web for compatible version of node.js for npm v5.5.1 and got node v10.15.1 which I downloaded installed with several system restarts but my node and npm still remain incompatible. Please what can I do?
You should use nvm which is the Node Version Manager, cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
commands:
nvm install <version> Download and install a <version>
nvm use <version> Modify PATH to use <version>
nvm ls List versions (installed versions are blue)
Helpful reads:
How can the default node version be set using NVM?
How to change node version with nvm

Node version not updating after "nvm use" on mac

I am trying to update my local node version from 8.9.0 to 8.10.0 using nvm. But it's not getting reflected. Here's what I tried:
node -v
-> v8.9.0
nvm use 8.10.0
-> Now using node v8.10.0 (npm v5.5.1)
node -v
-> v8.9.0
I am unable to get why it won't change. Please let me know what have I done wrong.
Adding few notes about my experience on debugging this problem.
First, I started out with the command provided by Jonathan which -a node and got the same output as op:
/usr/local/bin/node
/Users/<my-user>/.nvm/versions/node/v8.10.0/bin/node
Moving on to the next comment by Jonathan: Have you installed Node via Homebrew as well?, I tried uninstalling node by brew uninstall node and got and error that said it could not uninstall node as there was another program dependent on it. yarn.
And then realised that brew had installed its own version of node because I installed yarn through brew, which was overwriting the node version that I wanted to use through nvm.
Uninstalling brew's version of yarn+node fixed my problem.
I still needed yarn, and now I have to install yarn globally for each node version managed by nvm.
Inconvenient, I agree. But so is maintaining twenty thousand versions of node for each project so not very different in my opinion.
All of this was done on M1 MacOS and your output might vary based on your system.
Please ensure that when you input arch on command prompt, then output is i386.
This is achieved using Rosetta.
Following sequence of commands on terminal worked: -
nvm install 8.10.0
nvm install --lts
nvm ls
brew upgrade
arch -arm64 brew install n
n
Now select node version 8.10.0 using up or down arrow keys in keyboard and then quit from command prompt using command+q
Please do not try brew uninstall --ignore-dependencies node
Just check you environment variables first. It might be mapping to node#8.9.0.
You need to remove the environment variable first.
If you are also using volta. Volta may take precedence.
Use which -a node to verify.
If that is the case, use volta pin node#version to switch.
First check your nvm version installed on your local system. go to command prompt and type "nvm list" If you don't see the versions 8.10.0 in the list then install using command : "nvm install 8.10.0" and then try "nvm use 8.10.0".
For reference : http://www.tutorial-points.com/2018/11/nvm-installation-on-windows.html

Updating Node and NPM

On a Mac OSX, I want to update to the latest versions of node and npm which is currently v10.7.0
I installed homebrew and executed the following at the terminal.
brew update
brew upgrade node
Now, when I type
node -v
the terminal responds:
v6.10.2
And when I type
npm -v
the terminal responds:
6.2.0
It looks like I have earlier versions of Node.
But when I type
brew upgrade node
The terminal responds with
node 10.7.0 already installed
It looks like there's a discrepancy. On one hand, it's telling me I have an earlier version of node. On the other hand, it's telling me I have the latest version.
What can I do to install and get my machine to recognize the latest node version?
You probably need to link the new version using brew link node or brew link --overwrite node
I have been using nvm on my linux servers for a while and now prefer to use it (over homebrew) on my development mac as well -
curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Now just open a new shell (or source ~/.nvm/nvm.sh) and switch to whichever version you would like. Eg.
nvm install 10.7.0
nvm use 10.7.0

Can't update node globally with nvm?

I want to upgrade node to v8.3 globally. I'm working on the latest OSX and using v0.33.0 of nvm.
I can upgrade successfully in one bash shell:
$ which node
/Users/me/.nvm/versions/node/v8.1.0/bin/node
$ nvm install 8.3 --reinstall-packages-from=8.1
v8.3.0 is already installed.
Now using node v8.3.0 (npm v5.3.0)
Reinstalling global packages from v8.1.4...
Linking global packages from v8.1.4...
$ node -v
But then if I open a new shell, it's still pointing at the old version:
$ which node
/Users/me/.nvm/versions/node/v8.1.0/bin/node
$ node -v
v8.1.0
What am I doing wrong? I can't see anything in my bash profile pointing to the older version.
You need to also set your default node version, like this:
nvm alias default 8.3.0
This should set your version moving forward. Credit:
https://eric.blog/2016/08/23/set-default-node-version-with-nvm/

Resources