I just installed Node.js
and npm
(for additional modules).
How can I update Node.js and the modules which I'm using to the latest versions?
Can npm
do it, or do I have to remove and reinstall Node.js and npm to get the next versions?
I followed this steps in the npm
section.
This question is related to
node.js
linux
npm
node-modules
npm-update
Windows users should read Troubleshooting > Upgrading on Windows in the npm wiki.
The link above Troubleshooting#upgrading-on-windows points to a github page npm-windows-upgrade the lines below are quotes from the readme. I successfully upgraded from npm 2.7.4 to npm 3.9.3 using node v5.7.0 and powershell (presumably powershell version 5.0.10586.122)
First, ensure that you can execute scripts on your system by running the following command from an elevated PowerShell. To run PowerShell as Administrator, click Start, search for PowerShell, right-click PowerShell and select Run as Administrator.
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Then, to install and use this upgrader tool, run (also from an elevated PowerShell or cmd.exe):
npm install --global --production npm-windows-upgrade
npm-windows-upgrade
To update npm :
npm install npm@{version} -g
to update npm to the latest version:
npm install npm@latest -g
and to check the version :
npm -v
to update node js :
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
to check :
node -v
To update npm, the npm update npm -g
command didn't work for me (on windows). What did work was reinstalling npm according to the documentation: "You can download a zip file from https://npmjs.org/dist/, and unpack it in the same folder where node.exe lives." Make sure if you do this that you get rid of your previous installation first (though overwriting it will probably work ok...).
To update your modules, use the npm update command
sudo n list => show the list of installed versions sudo n stable => install latest stable version.
You can also use nvm to install latest version or change between different versions.
For latest npm version: npm install -g npm@latest
I understand this question is for Linux machine but just in case anybody is looking for a Windows solution, just go to the Node.js site, click the download button on the homepage and execute the installer program.
Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest 0.8.15 Node.js version running on my Windows 7 machine.
See the docs for the update
command:
npm update [-g] [<pkg>...]
This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.
Additionally, see the documentation on Node.js and NPM installation and Upgrading NPM.
The following original answer is from the old FAQ that no longer exists, but should work for Linux and Mac:
How do I update npm?
npm install -g npm
Please note that this command will remove your current version of npm. Make sure to use
sudo npm install -g npm
if on a Mac.You can also update all outdated local packages by doing
npm update
without any arguments, or global packages by doingnpm update -g
.Occasionally, the version of npm will progress such that the current version cannot be properly installed with the version that you have installed already. (Consider, if there is ever a bug in the update command.) In those cases, you can do this:
curl https://www.npmjs.com/install.sh | sh
To update Node.js itself, I recommend you use nvm, the Node Version Manager.
Go to "https://nodejs.org/en/" and then download either the latest or most stable versions. After downloading, Mac pkg installer updated the existing version. In linux: apt and windows installer will take care.
When I did the npm -v
from cmd it gave the most stable version which I have downloaded and installed from the above link.
xyz-MacBook-Pro:~ aasdfa$ node -v v8.11.1
This worked for me on Windows for updating just npm
(powershell
in Administrative mode):
npm --version
# 5.6.0
cd "C:\Program Files\nodejs"
rm "npm"
rm "npx"
mv "npx.cmd" npx.old.cmd
mv "npm.cmd" npm.old.cmd
# This is the important command
./npm.old.cmd install npm
rm *.old.cmd
npm --version
# 6.4.1
This fixed npm WARN npm npm does not support Node.js v10.12.0
which I had because chocolatey
installed incompatible node and npm?
Updating npm is easy:
npm install npm@latest -g
Use n module from npm in order to upgrade node . n is a node helper package that installs or updates a given node.js version.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
NOTE that the default installation for nodejs is in the /usr/bin/nodejs and not /usr/bin/node
To upgrade to latest version (and not current stable) version, you can use
sudo n latest
To undo:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n
If you get the following error bash: /usr/bin/node: No such file or directory
then the path you have entered at
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
if wrong. so make sure to check if the update nodejs has been installed at the above path and the version you are entered is correct.
I would advise strongly against doing this on a production instance. It can seriously mess stuff up with your global npm packages and your ability to install new one.
To Install nodejs version 12.x and latest npm version of Ubuntu 20 Latest version follow these steps to install using PPA COPY THE WHOLE COMMAND AND RUN
cd ~ && curl -sL https://deb.nodesource.com/setup_12.x -o && nodesource_setup.sh && sudo bash nodesource_setup.sh && sudo apt install nodejs && nodejs -v
source https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04
npm -v
View curent NPM version:
npm view npm version
Update npm to current version:
npm i -g npm
View all versions including "alpha", "beta" and "rc" (release candidate)
npm view npm versions --json
Reinstall NPM to a specific version chosen from the versions list - for example to 5.0.3
npm i -g [email protected]
Installing one version will automatically remove the one currently installed.
For Linux and iOS prepend commands with sudo
Just run the below scripts on console:
sudo npm i -g n
sudo n stable
sudo npm update -g npm
This will work for Linux and MAC only
As @devWL said, its NPM who takes care of updates, whenever new updates get released you will get information regarding how to update NPM. Just copy and run the command given by NPM & you are up to date.
In case of updating node.js.
And now you are up to date.
NOTE: If you update nodejs itself then it comes with its own version of NPM. NPM may again say to update later on. So then just do whatever it says in console. NPM will automatically make sure that you updated it.
Install npm => sudo apt-get install npm
Install n => sudo npm install n -g
latest version of node => sudo n latest
Specific version of node you can
List available node versions => n ls
Install a specific version => sudo n 4.5.0
I found this really neat way of updating node on David Walsh's blog, you can do it by installing n
:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
It will install the current stable version of node
.
EDIT: Please don't use n anymore. I recommend using nvm
. You can simply install stable by following the commands below:
nvm ls-remote
nvm install <version>
nvm use <version>
As you may already know, npm is currently bundled with node.js. It means that if you have installed node.js, you've already installed npm as well.
Also, pay attention to the node.js and npm release versions table that shows us approximate versions compatibility. Sometimes, versions discrepancy may cause incompatibility errors.
So, if you're a developer, it's kinda "best practice" to manage your development environment using one of the node.js version managers.
Here is a list and usage notes of some of the most popular:
If you're on macOS, you can use Homebrew.
Actually, it's not just a node.js version manager.
To install Homebrew to your Mac:
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
To install node.js and npm using Homebrew, run:
$ brew install node
Later, you will be able to update them using:
$ brew update && brew upgrade node
Also, you can switch between node.js versions as well:
$ brew switch node 0.10.26
npm will be upgraded/downgraded automatically.
n is most likely to rvm (Ruby Version Manager), and is used to manage node.js and npm versions simultaneously. It is written on pure Linux shell, and available as an npm module. So, if you already have any node.js version installed, you can install/update the n package through npm
:
$ npm install -g n
Downloading, installing and switching to node.js and npm versions is as easy as:
$ n 0.10.26
$ n 0.8.17
$ n 0.9.6
To download, install, and switch to the latest official release, use:
$ n latest
To download, install, and switch to the latest stable official release, use:
$ n stable
To switch to the previously active version (aka $ cd -
), use:
$ n prev
If you want to see the list of installed node.js versions, just run n
from your command line. The output will be something like the following:
$ n
0.10.26
• 0.8.17
0.9.6
Where the dot (•) means that it's a currently active version. To select another node.js version from the list, use Up
/Down
arrow keys and activate using the Enter
key.
To list the versions available to install:
$ n lsr
nvm is also like rvm, even the command names and usage are very similar.
To install nvm you can use the installation script (requires git
) using cURL
:
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
or wget
:
$ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
To download and install a specific node.js and npm version, use:
$ nvm install 0.10
Then, you can switch to the installed version, using:
$ nvm use 0.10
Also, you can create the .nvmrc
file containing the version number, then switch to the specified version using the following command:
$ nvm use
To see the list of installed node.js versions, use:
$ nvm ls
To list the versions available to install:
$ nvm ls-remote
nvm-windows is a node.js version management utility for Windows, ironically written in Go.
It is not the same thing as nvm. However, the usage as a node.js version manager is very similar.
To install nvm-windows, it is required to uninstall any existing versions of node.js and npm beforehand. Then, download and run the latest installer from releases.
To upgrade nvm-windows, run the new installer. It will safely overwrite the files it needs to update without touching your node.js installations.
nvm-windows runs in an Admin shell. You'll need to start Powershell or Command Prompt as Administrator to use nvm-windows.
Before using, you may also need to enable nvm-windows with the following command:
C:\> nvm on
To download and install a specific node.js and npm version, use:
C:\> nvm install 0.12
Then, you can switch to the installed version, using:
C:\> nvm use 0.12
If you want to see the list of installed node.js versions, use:
C:\> nvm list
To list the versions available to install:
C:\> nvm list available
When it comes to Linux
I suggest an Update Node Using a Package Manager:
Node comes with npm pre-installed, but the manager is updated more frequently than Node. Run npm -v to see which version you have, then npm install npm@latest -g
to install the newest npm update. Run npm -v
again if you want to make sure npm updated correctly.
To update NodeJS
, you’ll need npm’s handy n module. Run this code to clear npm’s cache, install n, and install the latest stable version of Node
:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
To install the latest release, use n latest
. Alternatively, you can run n #.#.# to get a specific Node
version.
When it comes to Windows/ macOS
I suggest using Installers on Nodejs.org
The Node.js downloads page includes binary packages for Windows and macOS — but why make your life more difficult? The pre-made installers — .msi for Windows and .pkg for macOS — make the installation process unbelievably efficient and understandable. Download and run the file, and let the installation wizard take care of the rest. With each downloaded update, the newer versions of Node and npm will replace the older version.
Alternatively, macOS users can use the npm and n instructions above.
When it comes to updating your node_modules
dependencies folder, I suggest skipping all the things that could cause you a headache and just go to your specific project and re-run npm install
again.
Before anyone does that, I suggest first checking your package.json
file for the following:
As a user of NodeJS packages, you can specify which kinds of updates your app can accept in the package.json file. For example, if you were starting with a package version 1.0.4, this is how you could specify the allowed update version ranges in three basic ways:
To Allow Patch Releases: 1.0 or 1.0.x or ~1.0.4
To Allow Minor Releases: 1 or 1.x or ^1.0.4
To Allow Major Releases: * or x
Explanation:
MAJOR version for when there are incompatible API changes. --> ~
MINOR version for when functionality is added in a backwards compatible manner. --> ^
PATCH version for when backward compatible bug fixes are done. --> *
Here is a simple fix for those who installed node
via Homebrew without npm
and later on struggled with npm
upgrade/installation using an official script. This approach assumes you have run the node
installation as follows:
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
If above failed then start from here. Remove npm
if any:
rm -rf ~/.npm-packages/lib/node_modules/npm
Download and unpack the latest version of npm
, currently at 5.6.0:
cd ~
curl -L https://registry.npmjs.org/npm/-/npm-5.6.0.tgz | tar xz
Move unpacked package into node_modules folder:
mv ~/package ~/.npm-packages/lib/node_modules/npm
Make sure your ~/.bash_profile
has following entries:
export NPM_PACKAGES="$HOME/.npm-packages"
export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
export PATH="$NPM_PACKAGES/bin:$PATH"
Source the file:
source ~/.bash_profile
Verify installation:
npm -v
I found one plugin which can help to update all npm packages.
First, you need to install an npm-check-updates plugin.here is the link npm-check-updates
npm i -g npm-check-updates
So this utility is installed globally, you can invoke it by simply writing as follow.
1) ncu -u
Here ncu is npm check updates.
2) npm install
So with these two commands, you can easily update npm packages.I hope this will help you to update packages easily.
Just run the following command in terminal as root/administrator:
npm i -g n
n stable
npm update -g npm
It has worked for me on Linux
Use NVM to manage node version, it will automatically take care of npm.
I just installed Node.js on a new Windows 7 machine, with the following results:
> node -v
v0.12.0
> npm -v
2.5.1
I then did the above described procedure:
> npm install -g npm
and it upgraded to v2.7.3. Except than doing npm -v
still gave 2.5.1.
I went to the System configuration panel, advanced settings, environment variables. I saw a PATH variable specific to my user account, in addition to the global Path variable.
The former pointed to new npm: C:\Users\PhiLho\AppData\Roaming\npm
The latter includes the path to node: C:\PrgCmdLine\nodejs\
(Nowadays, I avoid to install stuff in Program Files and derivates. Avoiding spaces in paths, and noisy useless protections is saner...)
If I do which npm.cmd
(I have Unix utilities installed...), it points to the one in Node.
Anyway, the fix is simple: I just copied the first path (to npm) just before the path to node in the main, global Path variable, and now it picks up the latest version.
<some stuff before>;C:\Users\PhiLho\AppData\Roaming\npm;C:\PrgCmdLine\nodejs\
> npm -v
2.7.3
Enjoy. :-)
Another way to do this on Ubuntu: use umake.
umake nodejs
installed the latest current version v11.14.0
.
Plus:
Minus:
These days you go to https://nodejs.org/en/download/
Run the setup required by you're operating system. It will detect any existing installation and get you the selected version correctly installed.
It's very late, but I give my answer so that it will help somebody who is stuck there. You can update in many ways as described above, so here I am discussing the most popular and easy way to update nodejs and npm.
1)Update via library n
2)Update via nvm
Open your terminal I am using Ubuntu (Linux)
1)You can install n as any node module (globally)
npm install -g n
OR
you can also install from the source if you want
cd /tmp
git clone --depth=1 https://github.com/tj/n
cd n
sudo make install
After installation hit the below command to install the latest version of node
n latest
now check node -v (you see the latest version is installed)
It will install the latest stable version of node.
n stable
Or you can install any version by adding version number against n like
n 0.10.33 # Install and use v0.10.33
You can check more regarding n in the following link click here
2)Now comes to second approach using NVM Install
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
After installation hit the below command to install latest version of node
nvm install node
You can list available versions using ls-remote:
nvm ls-remote
If you want to install a specific version
nvm install 6.14.4
To use any version after installation
nvm use node
Update npm to latest one
nvm install-latest-npm
Hope it will help!
I recently stumbled across this article: http://martineau.tv/blog/2013/12/more-efficient-grunt-workflows/ and the author mentions $ npm-check-updates -u && npm install
to update all dependencies.
This is a little off the topic but I ended up here on a similar search so thought it was worth the share.
First update npm
,
npm install -g npm@next
Then update node
to the next version,
npm install -g node@next
or npm install -g n@next
or, to the latest,
npm install -g node@latest
or npm install -g node
check after version installation,
node --version
or node -v
for nodejs should uninstall it and download your favorite version from nodejs.org for npm run below line in cmd:
npm i npm
For Linux, OSX, etc..
To install the latest version of NPM
npm install -g npm@latest
Or To Install the most recent release
npm install -g npm@next
Additional : To check your npm version
npm -v
If you are in a Windows Machine, I suggest going to the npm website
you should see this blog nodejs install with package-manager
Before you performance this command.
you show run sudo apt-get update
, make sure result is Reading package lists... Done, no ERROR
Step by Step (Debian):
sudo apt-get update
install 6_x
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
install 7_x
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
$ npm install -g npm stable
Worked for me to update from 1.4.28 to 2.1.5
Personally I use nvm
(Node Version Manager) which is a simple bash script to manage multiple active node.js versions and you can have multiple versions of node and global modules configured for different users at the same time.
You can check at this link: nvm
Also there is a windows version nvm-windows
The Best Way to handle Node Versions is By using NVM or node version manager after installation use the following commands:
nvm list (shows you the list of installed nodejs version)
nvm install nodeversion (to install the node version, if latest use @latest)
nvm use 10.515.. (to use a perticular node version)
Sometimes it's just simpler to download the latest version from http://nodejs.org/
Especially when all other options fail.
http://nodejs.org/ -> click INSTALL -> you'll have the latest node and npm
Simple!
For those who want to upgrade npm on windows,
Open Powershell(as administrator) and execute following commands sequentially,
>Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
>npm install -g npm-windows-upgrade
>npm-windows-upgrade -p -v latest
If you don't want to update to the latest version. Do this command:
npm install [email protected] -g
Replace 4.2.0 with whatever version you want. Here are all the release versions by Oct 3rd 2017: https://nodejs.org/en/download/releases/
I have developed a very simple and fast package to do this kind of update, atualiza can deal with global and project packages. In the later you can choose between the newest version or the bigger version that matches your current package.json
's rule. For global packages you don't have a rule so atualiza
will upgrade to newest always.
I think the best way to manage node.js is to use NVM. NVM stands for Node Version Manager.
It's a must-have tool for node.js developers!
You can install NVM using the following command, open terminal and run any one of the following:-
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
After installing this it's recommended to close the current terminal and open a new one since NVM will be adding some environment variables so terminal needs to be restarted.
I'll list down some of the basic commands for using NVM.
nvm ls-remote
nvm install v10.15.1
nvm ls
nvm uninstall v10.15.1
npm
on the current node versionnvm install-latest-npm
npm
packages from one version to another instead of manually installing each one of them!For Cygwin users:
Installing n (node version manager) in Cygwin
doesn't work, instead update node with:
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\pathto\nodejs\node.exe'
# Updating npm
npm i -g npm
Yes, you need to install wget
first.
You can follow this documentation to update the existing npm and node version to the next version.
This one is worked for me.
Just listened to an interview with the npm team on the latest episode of nodeup, and they recommended not using update
for the update from 1.x
to 2.x
. Instead, use:
npm install npm -g
sudo npm install npm@latest
I run this on Linux so I am not sure about other operating systems.
sudo apt-get update
sudo apt-get upgrade
This will tell the apt-get
package manager to update and upgrade all packages.
If you're using Windows: Go to https://nodejs.org/en/download/, download latest .exe
or .msi
file and install to overwrite the old versions
If you're using Ubuntu or Linux: Uninstall node.js
first then reinstall, e.g with Ubuntu ():
sudo apt-get remove nodejs
# assume node.js 8 is latest version
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs
node -v
npm -v
Remove node_modules
in your project folder and npm install
to make sure your application will run well on new node
and npm
version.
firstly, you check to latest version
npm -v
and then update npm through this cmd
npm install -g npm@latest (hit this command in your terminal)
and check to latest version now I defiantly sure you npm version upgrade
npm -v
and also you can download the latest version from this link here:-
and if you using linux then visit this stackoverflow question
Warning: if you need update Node from an old version (in my case v4.6.0
) it is better to re-install nodejs from scratch (download link: https://nodejs.org) otherwise npm will also update itself to a version that's not compatible with the new Node (see this discussion).
This is the error message that I got after updating Node (on Windows) with npm
$ npm install -g npm stable
[ . . .]
$ npm
C:\Users\me\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js:85
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supporte
d outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
After new installation npm works again:
$ npm -v
6.5.0
$ node -v
v10.15.0
Just with this code
npm install update
Check your package version: npm -v [package-name]
Update it: npm update [-g] [package-name]
using -g or --global installs it as a global package.
Also if you want to update to a particular version, follow this:
sudo npm cache clean -f
sudo npm install -g n
sudo n <specific version>
npm -v
(You may need to prefix these commands with sudo
, especially on Linux, or OS X if you installed Node using its default installer.)
You can upgrade to the latest version of npm using:
npm install -g npm@latest
Or upgrade to the most recent release:
npm install -g npm@next
By default, npm is installed alongside node in
C:\Program Files (x86)\nodejs
npm's globally installed packages (including, potentially, npm itself) are stored separately in a user-specific directory (which is currently
C:\Users\<username>\AppData\Roaming\npm
).
Because the installer puts
C:\Program Files (x86)\nodejs
before
C:\Users\<username>\AppData\Roaming\npm
on your PATH
, it will always use the version of npm installed with node instead of the version of npm you installed using npm -g install npm@<version>
.
To get around this, you can do one of the following:
Option 1: edit your Windows installation's PATH
to put %appdata%\npm
before %ProgramFiles%\nodejs
.
Remember that you'll need to restart cmd.exe
(and potentially restart Windows) when you make changes to PATH
or how npm is installed.
Option 2: remove both of
%ProgramFiles%\nodejs\npm
%ProgramFiles%\nodejs\npm.cmd
Option 3: Navigate to %ProgramFiles%\nodejs\node_modules\npm
and copy the npmrc
file to another folder or the desktop.
Then open cmd.exe
and run the following commands:
If you installed npm with the node.js installer, after doing one of the previous steps, do the following.
Option 1 or 2
%ProgramFiles%\nodejs\node_modules\npm
and copy the file named npmrc
in the new npm folder, which should be %appdata%\npm\node_modules\npm
. This will tell the new npm where the global installed packages are.Option 3
%ProgramFiles%\nodejs\node_modules\npm
The Node installer installs, directly into the npm folder, a special piece of Windows-specific configuration that tells npm where to install global packages. When npm is used to install itself, it is supposed to copy this special builtin
configuration into the new install. There was a bug in some versions of npm that kept this from working, so you may need to go in and fix that up by hand. Run the following command to see where npm will install global packages to verify it is correct.
npm config get prefix -g
If it isn't set to <X>:\Users\<user>\AppData\Roaming\npm
, you can run the below command to correct it:
npm config set prefix "${APPDATA}/npm" -g
Incidentally, if you would prefer that packages not be installed to your roaming profile (because you have a quota on your shared network, or it makes logging in or out from a domain sluggish), you can put it in your local app data instead:
npm config set prefix "${LOCALAPPDATA}/npm" -g
...as well as copying %APPDATA%\npm
to %LOCALAPPDATA%\npm
(and updating your %PATH%
, of course).
Everyone who works on npm knows that this process is complicated and fraught, and we're working on making it simpler. Stay tuned.
Source: https://docs.npmjs.com/troubleshooting/try-the-latest-stable-version-of-npm
Source: Stackoverflow.com