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.
I have had the latest version of node(v12) by running
brew install node
but I want to have the previous version(v10)
I have uninstalled node and installed the previous version by running
brew install node#10
now when I run node --version I get nothing. How can I link the node keyword to what now is node#10 on mac?
There is nothing like linking the node keyword to node#10.
The #10 represents the current version of the environment installed.
Check if you have installed Xcode. Node.js and some of its components will rely on Xcode's Command Line Tools package.
You can follow the blog for a correct installation: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-and-create-a-local-development-environment-on-macos
I installed NodeJs with the following commands:
brew install node
It downloaded the version 5.5.0 of NodeJs.
I want the version 4.1.2 (for Ionic compatibility).
How to download this specific one?
I can't run brew switch node 4.1.2 since I've never downloaded it before.
May I suggest using nvm instead?
With nvm you can switch between node versions really easy:
nvm install 4.2
And you can install multiple versions of node and switch between them as you wish.
You can search available versions of node to install by running:
brew search node
The closest version would be "node4-lts". To obtain that version, run:
brew install homebrew/versions/node4-lts
I just ran brew upgrade node and it successfully upgraded Node to version >=4, however node --version returns the old version:
My-MacBook-Pro:~ me$ node --version
v2.3.0
My-MacBook-Pro:~ me$ brew upgrade node
Error: node 4.1.1 already installed
How can I have node use the newest version instead of 2.3.0?
First of all, did you run:
brew update
prior to:
brew upgrade
You could also try linking to the correct version:
brew switch node <version>
To see which versions of node homebrew knows about:
brew info node
If you are on a MAC (as you state) then i would highly recommend using NVM to manage your node and npm versions - and avoid homebrew for this altogether (especially if support for more than one version is likely). This is the best way to install node on a MAC imho.
The easiest way to upgrade from Node 0.12.x (io <4.x) to 4.x on OS X is by using the OS X installer from https://nodejs.org/dist/v4.2.4/node-v4.2.4.pkg.
It automatically symlinks all the required binaries.
brew unlink node followed by:
rm '/usr/local/include/node/common.gypi' followed by:
brew link --overwrite node
This fixed it for me.
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.