How do I change my Node version after installing it using Homebrew? - node.js

After installing Node using Homebrew on OSX 10.11.6 I now have a copy of node installed at
/usr/local/Cellar/node/10.7.0.
However, the version of Node that appears when I run
$ node -v
in terminal is
v0.12.7
I would like OSX terminal to reference the v10.07 of Node I just installed via Homebrew when I type
$ node
How do I change which node version that OSX terminal recognizes?

You should try using NVM. It allows you to install multiple versions of Node on your machine and switch between them conveniently:
see NVM docs

Related

Can't switch to another version of Node

I can't switch any more to another of Node versions I Installed via NVM.
So far I did it by using these commands:
nvm list //to check Node versions available on my machine
nvm use X.X.X //to pick a version
node -v //to check if I'm using the Node version I picked
Now If I run those commands I see that the current node version is always 14.17.0. This is what Visual Studio Code terminal shows me:
$ nvm list
14.0.0
12.11.0
12.2.0
12.0.0
11.11.0
10.24.1
8.16.2
$ nvm use 12.0.0
Now using node v12.0.0 (64-bit)
$ node -v
v14.17.0

How to get my system to use node version installed by Homebrew?

On OS X, when I run node --version I get v12.9.1. I ran brew upgrade node and it warned me Warning: node 15.3.0 already installed. I ran brew uninstall node, but then when I ran node --version I still got v12.9.1.
**What I Want To Know: **
Why does my system say that my node version is 12.9.1 when 15.30.0 is installed? How can I get it so that my system is using 15.3.0 instead of 12.9.1?

Which version of node am I using?

I recently updated my version of node using homebrew to begin learning angular and ran into something curious. Upon using:
brew upgrade node
It responds:
node 13.7.0 already installed
But then when I check which version, this happens.
node -v
v10.15.3
So am I really using 13.7? Because according to https://angular.io/guide/setup-local I need version 10.9 or better. So 10.15 would certainly be a problem.
Try running this command which -a node in your command shell.
That will list all the node binaries in your PATH. More than likely your path is mucked up and the MacOS installed version of node is found in the path before the brew-installed version of `node.

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

Resources