Unable to change version of node with brew switch - node.js

I'm trying to use node 8.9.1 but when trying to update using brew it says 8.9.1 is already installed
James-MacBook:~ james$ brew upgrade node
Error: node 8.9.1 already installed
But when checking the version it shows
James-MacBook:~ james$ node --version
v0.10.48
So then I tried to switch to 8.9.1
James-MacBook:~ james$ brew switch node 8.9.1
Cleaning /usr/local/Cellar/node/8.9.1
7 links created for /usr/local/Cellar/node/8.9.1
But it is still showing as 0.10.48
James-MacBook:~ james$ node --version
v0.10.48

It sounds like you have some version of node that is installed without using Homebrew.
First of all, check if you installed your node with nvm by check if you have a .nvm directory in home directory ls -la
if you do, remove that directory
brew update && brew install node#8 (whichever node you want)
brew unlink node#0
brew link --force node#8
Do brew update && brew upgrade node#8
Happy coding

Nvm package... kind of slows down your terminal upon startup. I found it annoying....
You can always just uninstall node and install node that’s compatible with npm on
Nodejs.org link below
All node version link <- !
look for pkg if your mac user, and msi for windows users

Related

How to link an old version of node in mac using homebrew

I am trying to link to an older version of node using homebrew in my mac (because netlify doesn't work with v17 - which is my default).
When I search which versions of node I have installed, I can see that both 16 and 14 are available.
brew search node
==> Formulae libbitcoin-node node ✔ node-sass node#12 node#16 nodebrew nodenv
llnode node-build node#10 node#14
node_exporter nodeenv ode
I expect to be able to run brew unlink node (which works fine) and then
brew link node#16 or brew link node#14, but in both cases, I get an error that says:
Error: No such keg: /usr/local/Cellar/node#16
How can I ask homebrew to use an old version of node?
This is what I did:
brew install node#16
export PATH="/opt/homebrew/opt/node#16/bin:$PATH" (you need to put into ~/.bash_profile or ~/.zprofile to persist the change)
And then I can see the node points to node##16
$ which node
/opt/homebrew/opt/node#16/bin/node
$ node --version
v16.14.2
You could do
brew link --overwrite node#16

I have nodejs but not able to upgrade it by homebrew, what should I do?

I am on Mac 11.6 (20G165).
I have node.js v10 installed and want to upgrade to v12.
However, when I type brew upgrade node, I got this:
$brew upgrade node
Error: node not installed
I think it's because I didn't install node via homebrew before. But it's been such a long time and I couldn't remember what exact source/channel did I choose to install node long ago.
So what I can do to fix all this?
If you have NVM installed you can run:
nvm install 12.14.1
then set the default Node with:
nvm alias default v12.14.1
Validate:
node -v
As you said, the problem is with the installed version. you are not installed nodejs with homebrew previously.
So, if you want to install it with brew and use its benefits (like upgrading) try to uninstall the currently installed version with the instruction in this post.
Then, install the latest version via brew command:
brew install node
More on brew documentation.

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.

How to properly upgrade node using nvm

Is it possible to upgrade node right in place, instead of manually installing the latest stable version?
I have installed node.js version 5.0 with nvm, but now I want to update it to 5.4. I'm trying to avoid having to manually reinstall all of my global packages (e.g. by running npm install -g grunt-cli bower yo yoman-angular-generator blabla blablablabla...).
This may work:
nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION
For example:
nvm install 6.7 --reinstall-packages-from=6.4
then, if you want, you can delete your previous version with:
nvm uninstall OLD_VERSION
Where, in your case,
NEW_VERSION = 5.4
OLD_VERSION = 5.0
Alternatively, try:
nvm install stable --reinstall-packages-from=current
You can more simply run one of the following commands:
Latest version:
nvm install node --reinstall-packages-from=node
Stable (LTS) version: (if currently in use)
nvm install "lts/*" --reinstall-packages-from="$(nvm current)"
This will install the appropriate version and reinstall all packages from the currently used node version.
This saves you from manually handling the specific versions.
Kudos to #m4js7er for commenting about the LTS version.
⚡ TWO Simple Solutions:
To install the latest version of node and reinstall the old version packages just run the following command.
nvm install node --reinstall-packages-from=node
To install the latest lts (long term support) version of node and reinstall the old version packages just run the following command.
nvm install --lts /* --reinstall-packages-from=node
Here's a GIF animation to support this answer:
if you have 4.2 and want to install 5.0.0 then
nvm install v5.0.0 --reinstall-packages-from=4.2
the answer of gabrielperales is right except that he missed the "=" sign at the end. if you don't put the "=" sign then new node version will be installed but the packages won't be installed.
source: sitepoint
Here are the steps that worked for me for Ubuntu OS and using nvm
Go to nodejs website and get the last LTS version (for example the version will be: x.y.z)
nvm install x.y.z
# In my case current version is: 14.15.4 (and had 14.15.3)
After that, execute nvm list and you will get list of node versions installed by nvm.
Now you need to switch to the default last installed one by executing:
nvm alias default x.y.z
List again or run nvm --version to check:
Update: sometimes even if i go over the steps above it doesn't work, so what i did was removing the symbolic links in /usr/local/bin
cd /usr/local/bin
sudo rm node npm npx
And relink:
sudo ln -s $(which node) /usr/local/bin/nodesudo && ln -s $(which npm) /usr/local/bin/npmsudo && ln -s $(which npx) /usr/local/bin/npx
Node.JS to install a new version.
Step 1 : NVM Install
npm i -g nvm
Step 2 : NODE Newest version install
nvm install *.*.*(NodeVersion)
Step 3 : Selected Node Version
nvm use *.*.*(NodeVersion)
Finish
Bash alias for updating current active version:
alias nodeupdate='nvm install $(nvm current | sed -rn "s/v([[:digit:]]+).*/\1/p") --reinstall-packages-from=$(nvm current)'
The part sed -rn "s/v([[:digit:]]+).*/\1/p" transforms output from nvm current so that only a major version of node is returned, i.e.: v13.5.0 -> 13.
For Windows 11 this worked for me on cmd, used with admin rights:
Prerequisite, in case you just installed NVM, is to open a new cmd window after nvm installation.
See installation instructions here: https://github.com/coreybutler/nvm-windows
Get installed versions, using
nvm list
Get current version
nvm current
Install latest version
nvm install latest
Check installed versions to see for newer version, again using
nvm list
Set current version to the latest (cmd with admin rights), you just installed in the previous step
nvm use PUT_VERSION_NUMBER_TO_BE_USED
You can check again if the change was successful using
nvm list
Remove old version, if no longer needed
nvm remove PUT_VERSION_NUMBER_TO_BE_REMOVED
If you want to use the LTS version, install using
nvm install lts
Here's the steps to upgrade NodeJs version:
Run nvm install node (will install latest version). Alternatively, you
can specify a specific version by running nvm install <node_version>.
Run nvm use <node_version> to use it.
If you want to make it the default version on your machine, run nvm alias default <node_version>.
Additional notes:
To find out what node versions you have on your machine and which one is set as your default one, use nvm list command.

The best way to install node.js on a Mac?

Homebrew and the Node download page install node.js in different locations that apparently conflict. Brew will complain after a 'brew doctor' if both locations are used.
So, is there a preferred way to put node on my Mac(Yosemite 10.10.5).
This is what I'm getting now while attempting to install node via brew.
node-4.1.0 already installed, it's just not linked
DONs-iMac:Erlang-Elixir donfox1$ brew link node
Linking /usr/local/Cellar/node/4.1.0...
Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.
Have you tried chmoding 755 /usr/local/share/systemtap/tapset so it is writable? That could fix it?
chmod 755 /usr/local/share/systemtap/tapset
brew link node
Also try this if it does not work (may work):
brew cleanup
brew link node
brew uninstall node
brew install node
sudo chown -R $USER /usr/local/share/
brew doctor
brew install node
Uninstall node:
sudo rm -rf /usr/local/share/systemtap/ && brew uninstall node
and install nvm with brew - so you can control you node versions.
Read this article: suggested way to install npm with brew
If you are not sure about what version of node you need now and potentially need in the future I would also reccomend to install NVM - node version manager.
Download the nvm install script via cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
Ensure that nvm was installed correctly with nvm --version, which should return the version of nvm installed.
Install the version of Node.js you want
Install the latest version with nvm install node
Use the latest version with nvm use node
Install the latest LTS version with nvm install --lts
Use the latest LTS verison with nvm use --lts
You can also check the tutorials:
installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu
Best way to install and use nvm on Mac

Resources