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.
nvm install lts/* --reinstall-packages-from=node
. After that you can cleanup your versions with nvm uninstall [old version]
. You can list all installed versions with nvm ls
.
--reinstall-packages-from=node
You can use different global environments for versions 6, 8 and 10.
nvm install lts/* --reinstall-packages-from=node
but it gave me error saying Version 'lts/*' not found - try 'nvm ls-remote' to browse available versions.
I am using NVM version 0.30.1, maybe my NVM is too old. I end up manually replacing lts/*
with 10.15.2/*
to get it to work.
zsh: no matches found: lts/*
simply quote the lts/* argument to prevent Z shell from interpreting the * as a globbing wildcard: nvm install 'lts/*' --reinstall-packages-from=node
⚡ 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 --reinstall-packages-from is provided, it must point to an installed version of node.
node
did not point to latest version installed. Or you need to update nvm.
nvm
in the favor of an extremely fast and low-profile script called n
. I made a 10-minute video on it — talking about why I moved to n
and how you can use it. The video is available at nodecli.com/nodejs-install-n
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
https://i.stack.imgur.com/zCtUx.png
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/node
sudo ln -s $(which npm) /usr/local/bin/npm
sudo 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
npm WARN deprecated nvm@0.0.4: This is NOT the correct nvm. Visit http://nvm.sh and use the curl command to install it.
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
Success story sharing
nvm install stable
remove all the packages installed including installed node rather updating them?nvm ls-remote
you can see all releases.nvm install node --reinstall-packages-from=$(nvm current)
. That'll update Node.js to latest version and reinstall npm global packages from whatever the previous version was.nvm deactivate
and try again.