How can I update Node.js and NPM to their latest versions?
Asked Answered
M

67

2155

I just installed Node.js and NPM (Node Package Manager). I installed NPM for access to additional Node.js modules.

After I installed Node.js and NPM, I noticed that neither were the latest versions available.

How do I upgrade Node.js, NPM, and my Node.js Modules to their latest versions? Do I need to uninstall Node.js and NPM, and reinstall the latest versions?

Here is the link to what I have tried so far. This link is a section from npm.

Mohandas answered 4/6, 2011 at 14:28 Comment(10)
I was point out that even a more correct way of updating npm is to use nodesource.com See https://mcmap.net/q/45701/-how-to-update-npmAdiaphorism
Possible duplicate of How to update npmGoodoh
@Motocarota Look at the dates, other question is duplicated of this one...Leslee
there is the tool nvm wich gives you the option to have more than one running versions of node+npmInglis
Things have changed for the better since this was first asked (if you don't need version managemenent). See Update Node (Windows, Mac & Linux).Tandie
Simplest solution (without commandline) Download the version from: nodejs.org/en It replaced my existing versions and everything's working swimmingly.Industrialist
use npx <package-name> instead. This will use latest version directly from repo to your project. and uninstall outdated packages from global environment using npm uninstall -g <package-name>Andris
Just use NVM (github.com/nvm-sh/nvm) and check the documentation regarding how to alias the latest LTS versionEvelynneven
Does this answer your question? How do I update Node.js?Apparent
easiest way is to use npm update -g npmSimplistic
T
2142

Use:

npm update -g npm

See the documentation 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 it 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 doing npm 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.

Tailing answered 4/6, 2011 at 14:48 Comment(26)
Thanks! I had to use the curl method to update from 1.0.6 to 1.0.23.Herrington
I dont understand what the [<name> [<name> ...]] suppose to mean ? is there an example make use all of those parameter ?Bologna
@runrunforest - it just means you can put any number of package names after the command, eg. npm update package1 package2 package3Hemiplegia
You might need to sudo that install script, like so: curl https://npmjs.org/install.sh | sudo shThomasinethomason
npm update npm -g didn't work for me on windows - it completed without output but npm remained the same version (1.3.11 when the most recent version is 1.3.14)Crankcase
I kept getting a 301 when I tried the curl command, so I just downloaded the script and ran sh install.sh.Evora
This is the path that is working for me (mind the www and the sudo): curl https://www.npmjs.org/install.sh | sudo shShaffert
also have curl follow redirects with -L curl -L https://npmjs.org/install.sh | sudo shDecanter
I did it like you said npm update npm -g and now I don't have npm as a command.Fulfillment
@Sumit well I decided to get rid of node and npm installation via npm and I downloaded the binary installer from webpage. (I'm using MacOsX)Fulfillment
For updating from 1.x to 2.x the npm team recommends instead using npm install npm -g.Freberg
I tried all this suggestions (I get "It worked" and 2.1.16 during update) but my npv -v still gives me a sad 1.4.28 :(Phage
After running this I needed to run sudo chown -R [username] ~/.npmAldershot
npm install -g npm on mac removes current version of npm. correct command is sudo npm install -g npmMethodist
"Occasionally, the version of npm will progress such that the current version cannot be properly installed with the version that you have installed already." How can you tell when this is the case?Crudden
And btw: I needed to restart my bash for the update to work. Got confused when the update reported "It worked!" but npm --version still yielded my old version. Restarting my console and npm now reports the correct, up-to-date version :)Niklaus
Indeed, npm update -g npm just blew up npm on Windows for me. Have to reinstall node now. Ugh.Kunz
Using npm to install a new version of itself. I smell things blowing up.Polydactyl
I would maybe reword the bit about mac to say that they "may" need to use sudo. You can install npm in a way that it doesn't require sudo, and I would argue that's the correct way to install it.Headword
Please do not sudo when using npm install -gArrearage
DON'T use sudo npm install -g npm! This will uninstall it!Chalk
I tried, everything was fine, but after npm--version It shows me 5.6Roundhouse
After the above erased npm as a command, and after going down a long rabbit hole, this is what ended up working for me: curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -. (Using CentOS7)Desecrate
stil am getting You are running version v10.0.0 of Node.js, which is not supported by Angular CLI 8.0+.Cm
npm i -g npm-upgradePassenger
@Chalk first, why is this the case? second, this should really be added to the answer, as most would assume you need to use sudoGibber
D
522

I found this really neat way of updating Node.js 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.js.


But 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>
Dorsett answered 13/6, 2013 at 20:38 Comment(16)
Refuses to run for windows x64 (but does with win32 apparently). That's not in keeping with the Node.js project.Distilled
Not supported for Windows. I realize it would be easier to just use Linux, but at work, I am not free to choose my OS. As @Distilled says, the spirit of the Node.js project is to be cross-platform, and this isn't.Federalese
In Windows, you can simply download the newest version of node and install it. It'll upgrade both node and npm.Headstrong
In windows 10 you need to download the installer from nodejs.org/en as this command don't work. I am not talking about the sudo that makes no sense in windows I meant the commands.Fioritura
I was looking at this and saying there is No way that this may work and it did work forFiche
Don't run npm cache clean -f in Windows!Aaberg
If you don't want or you can't use sudo, you can set the N_PREFIX envvar, before using n.Horacehoracio
That blog post now starts with the following message "This method of upgrading node is now unstable and should not be used. The best way to manage Node.js versions is to use NVM: Node Version Management.!"Urnfield
Why did you said 'Please don't use n anymore' ? Any particular reason ?Thoer
I do not know why David Walsh said n was unstable at the time, but that blog was from six years ago and n is still being maintained. Repeating other commenters, n does not run on Windows. And neither does nvm.Sweetsop
nvm-windows runs on windows and uses the same syntax. So yes, nvm is essentially cross-platform. "n" had admin right issues for me. I prefer nvm. But use whatever works...Villanelle
@SerjSagan I ran that command npm cache clean -f on Win 8.1 way before I read your comment and it just hung.... what happened? I am still trying to update to at least npm 6.13.x to use Angular 8. I had npm 6.10.x running BEFORE I installed latest stable node.js (12.18.4) but after that install, npm version was changed to 3.8.0 and I haven't been able to update it using various commands npm update -g npm and such.Chanterelle
I've been using n for years without any issues. Highly recommended!Poohpooh
Fast forward to 2022, n still does what it promises even for old version of MacOS. Apparently still a favorite along with nvm. Test result is here.Strident
I'm on macOS and have been using n for years. Quite happy with it - it's easy to use and does what it says on the can.Overture
There is a version of nvm for Windows as well.Mol
R
432

Updating npm is easy:

npm install npm@latest -g
Redeeming answered 13/3, 2015 at 1:9 Comment(7)
This causes fatal error, at least for mac users see hereSheridansherie
Using windows 10 and node v5.7.0 the command npm install npm@latest -g failed to upgrade from npm 2.7.4 to npm 3.9.3.Appropriate
In Laravel homestead this didn't work. I still have the same version, even after provission.Ironmaster
Thanks this worked for me, its pretty simple. But i had to sudo npm install npm@latest -g thats all. UpvotedFilmy
This is also the official answer: docs.npmjs.com/getting-started/installing-nodeArmenian
Using this command with sudo updated the npm version to 6.13.4 (as per the logs). But, when I checked version with command 'npm -v', it still shows the older version i.e. 6.4.1 Do I need to enable the recently installed version?Drais
Quit the terminal where you run the npm install -g npm and retryAla
H
191

I understand this question is for a 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 the Next button, I got the latest 0.8.15 Node.js version running on my Windows 7 machine.

Hollo answered 7/12, 2012 at 20:25 Comment(6)
yeah. this worked for me. Im on windows. the n method didnt work. wish there was a better way of doing it.Babul
This is the best and easiest way to upgrade node on windows. worked for me just fine. Thanks anmolEndoscope
if you're updating from npm v1.x to 2.x on Windows, you may have delete ‘npm’, ‘npm.cmd’ files from “C:\Program Files\nodejs” after installing or udpating npm. See: escapologist.wordpress.com/2014/09/29/…Voiture
Don't forget to reboot afterwards!Schizomycete
This works with Windows 10, and both Node and npm update. Very slick.Arnhem
For me, for whatever reason, I needed to first uninstall Node (which didn't work), so I manually removed programfiles\node and c:\users\<myuser>\AppData\Roaming\npm and npm-cache, then did a fresh install of node and then ran npm install npm@latest -g and at that point it finally workedIbbie
C
176

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 kind of "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:

Homebrew (macOS)

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 (macOS, Linux)

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

Output:

  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 (macOS, Linux)

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 (Windows)

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:

nvm on

To download and install a specific Node.js and npm version, use:

nvm install 0.12

Then, you can switch to the installed version, using:

nvm use 0.12

If you want to see the list of installed Node.js versions, use:

nvm list

To list the versions available to install:

nvm list available
Compotation answered 7/3, 2014 at 15:45 Comment(4)
I like this answer. +1 ! But it would have been even more useful to accompany it with some sort of explanation about the different package managers. Ie; why I should use one over the other. I would really help to give context..Pericles
with command "brew update && brew upgrade node" , npm doesn't get updated to latest version as mentioned "...NPM will be updated as well.."Accusatorial
I generally like homebrew but the fact it requires an update before I can upgrade npm on it is painfully slow...Software
can you please explain "npm will be upgraded/downgraded automatically." which command does this ?Accusatorial
R
131

First check your NPM version

npm -v

1) Update NPM to current version:

View curent NPM version:

npm view npm version

Update npm to current version:

npm i -g npm


2) List all available NPM versions and make a custom install/update/roll-back

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

Ranchero answered 7/6, 2017 at 21:51 Comment(2)
I ran into bundle of errors including Error: EACCES: permission denied, unlink running above command with sudo workedGunstock
@DevWL, I'm trying your solution now. When I ran the npm view npm versions --json command, I got a TON of listings of versions beginning at "1.4.26" - "7.0.0-beta.12" so I'm running npm i -g [email protected] -- it appears to be taking a while (currently fetch -> lock is running but looks hung) fingers-crossedChanterelle
M
67

Upgrading for Windows Users

Windows users should read Troubleshooting > Upgrading on Windows in the npm wiki.

Upgrading on windows 10 using PowerShell (3rd party edit)

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
Mirilla answered 1/12, 2014 at 19:29 Comment(2)
or just run: npm install -g npmFragrance
No Gal, you are confusing the issue, running npm install -g npm does not work on Windows, have you read the issues Windows users have had (listed above ?). Use the Powershell method as shown in Surf's answer. Thanks smurf , finally managed to upgrade yeeehaaaa!Subinfeudate
W
66

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 --versionor node -v

Wheatear answered 20/12, 2017 at 15:37 Comment(0)
R
59

SIMPLY USE THIS

npm i -g npm

This is what i get promped on my console from npm when new update/bug-fix are released:

enter image description here

Ranchero answered 7/6, 2017 at 3:17 Comment(1)
after I ran this I had to exit the bash terminal and restart to see the changes. Because the path to npm changed during the update process and for some reason it kept executing the old version which showed the older version of course when you executed npm -vSperrylite
C
33
  • To update Node.js, use nvm (or nvmw for Windows).

  • 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

Crankcase answered 16/11, 2013 at 20:28 Comment(3)
npm update npm -g worked for me. I run OSx, and have node installed via homebrew, however, brew upgrade node won't run if you already have the latest node version running, as I did. Piece o' cake.Saleable
npm install -g npm@latest worked for me on Windows8 https://mcmap.net/q/44979/-how-can-i-update-node-js-and-npm-to-their-latest-versionsChirk
@Chirk I tried that command, it didn't work for me on Win 8.1. npm still had old version 3.8.0 even though my previous version was 6.10.x. I needed to upgrade npm to at least 6.11.x for Angular. Now I can't seem to get rid of the old version.Chanterelle
D
31

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/nvm-sh/nvm/v0.39.0/install.sh | bash

or

wget -qO- https://raw.githubusercontent.com/nvm-sh//nvm/v0.39.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.

  • This will fetch all the node versions from the internet. All node versions from beginning till date will be shown, It will also mention LTS versions alongside.
nvm ls-remote 
  • This will show you the recommended versions of npm and node you should use. (This works only if you already have a version of npm installed, if not use the above command)
npm doctor
  • This will install the node version which you want (version list is obtained using the above command)
nvm install <version recommended by 'npm doctor' or 'nvm ls-remote'>

for example nvm install v14.18.1

  • This command will give us the list of node versions that are installed locally
nvm ls
  • This command is used to remove the node version that you want from your computer
nvm uninstall v10.15.1
  • The following command will help you upgrade to the latest working npm on the current node version
nvm install-latest-npm
  • NVM can be used to manage multiple node versions simultaneously
  • It can also help you install all the global npm packages from one version to another instead of manually installing each one of them!
  • There are many other uses of nvm the details of which and the commands can be found here Node Version Manager
Dripps answered 14/2, 2019 at 17:50 Comment(1)
Thanks @lightwing for updating links! :)Dripps
S
26

Try the latest stable version of npm

See what version of npm you're running:

npm -v

Upgrading on *nix (OSX, Linux, etc.)

(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

Upgrading on Windows


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 npmrcfile to another folder or the desktop. Then open cmd.exe and run the following commands:

cd %ProgramFiles%\nodejsnpm install npm@latest

If you installed npm with the node.js installer, after doing one of the previous steps, do the following.

  • Option 1 or 2

    • Go into %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

    • Copy the npmrc file back into %ProgramFiles%\nodejs\node_modules\npm

A brief note on the built-in Windows configuration

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

Shortening answered 8/8, 2018 at 0:8 Comment(1)
if devWL's solution doesn't work, I'm going to try yours. Thanks for the indepth answer. At this point, I'm wondering should I just uninstall Node and NPM -- it has taken me all day to try to fix this just so I can run Angular apps. I installed Node 12.18.4 today and thought it would update npm, but instead, when I run npm -v now, I get 3.8.0 as version when it previously was 6.10.x. Frustrating...Chanterelle
L
22
$ npm install -g npm stable

Worked for me to update from 1.4.28 to 2.1.5

Louvain answered 25/10, 2014 at 11:32 Comment(0)
C
19

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

Cleave answered 26/5, 2017 at 11:22 Comment(0)
I
17

To install the latest version of npm using npm:

sudo npm install npm@latest

I run this on Linux so I am not sure about other operating systems.

On Linux you can also run:

sudo apt-get update
sudo apt-get upgrade

This will tell the apt-get package manager to update and upgrade all packages.

Investment answered 14/5, 2020 at 13:49 Comment(3)
For Linux users. To solve "Error: EACCES: permission denied", you can sudo command before running npm install. sudo npm i npm@latestKristiankristiansand
Or you can log in as root if you don't want to use sudoInvestment
You will typically want to npm install npm -g, right?Habitforming
C
16

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. :-)

Conduct answered 22/3, 2015 at 15:43 Comment(3)
did you put this as the last entry in your Environment Variables Path?Chanterelle
@Chanterelle It is not important, the important part is that the path to npm is before the path to nodejs. And, of course, you must have no other paths to identical names before these!Conduct
thanks. I'll keep this in mind. I still don't understand why when I installed node 12.x the other day, my npm version went backwards to 3.8.x when it was at version 6.x.x.Chanterelle
H
15

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

Hade answered 3/9, 2017 at 9:18 Comment(2)
What is the difference between the latest and the most recent?Amathist
@Chris Lang recent is the newest version but the latest is the newest stable versionHade
V
14

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.

Varioloid answered 29/1, 2014 at 16:52 Comment(3)
david-dm.org And this just appeared as a comment from the post I cited. Seems perfect...Varioloid
To be clear, npm-check-updates is another package that needs to be installed.Treadway
The link is broken: "404: NOT_FOUND"Melquist
O
14

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

Odaodab answered 29/11, 2017 at 9:45 Comment(0)
Y
14

You could try this

npm install -g npm@latest

Yeaton answered 25/3, 2022 at 21:20 Comment(0)
I
13

You can upgrade to the latest version of npm using:

npm install -g npm@latest
Ineluctable answered 20/7, 2022 at 10:32 Comment(0)
A
12

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
Aegir answered 5/6, 2017 at 9:14 Comment(0)
S
11

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!

Shaffert answered 27/6, 2014 at 22:47 Comment(6)
Definitely simpler, but doesn't always work. I've struggled with all of the above suggestion and some more - none worked on my mac. Going to nodejs.org fixed it.Shaffert
in that case, you probably installed it in a bad way to begin with. Node/npm is one of those you want to prefix your installation so you don't need sudo for everything.Ragen
I probably installed it normally using brew or the installer. It might have been a specific bug in a specific npm version. I will probably never know and its probably doesn't matter - it was updating perfectly since than using npm update.Shaffert
This worked for me, thanks. I was having issues getting to the latest, and screwed things up when I unknowingly emptied the npm cache, heh. Had to (re)install the msi (on Windows) to get fully updated. Worked perfectly.Borlow
If you're using OS X or Windows, the best way to install or update Node.js and npm is to use one of the installers from the Node.js download link , when I were downloaded and extracted, it simply updated node and npm version on my macbook pro os x 10.13.Aldin
@Aldin I had npm 6.10.x previously on my box. I went to node.js and downloaded and installed latest stable version 12.18.4 and it did not update my npm on Windows 8.1. What it did was install an OLDER version of npm (3.8.0) which was frustrating and I'm still trying to find out how to fix this. I don't know why it shouldn't be as simple as going to the node.js site, downloading and installing would make the proper updates.Chanterelle
F
11

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

Freberg answered 20/10, 2014 at 6:29 Comment(0)
S
9

Just with this code

npm install update
Sit answered 30/11, 2015 at 16:5 Comment(0)
K
9

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. --> *

Kenneth answered 5/9, 2018 at 6:12 Comment(0)
P
8

for nodejs should uninstall it and download your favorite version from nodejs.org for npm run below line in cmd:

npm i npm
Pledgee answered 8/5, 2018 at 2:57 Comment(0)
A
8

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
Almucantar answered 3/1, 2019 at 11:25 Comment(0)
A
7

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>
Abirritant answered 29/3, 2016 at 6:58 Comment(1)
npm WARN using --force I sure hope you know what you are doing.Lied
H
7

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

Harpp answered 26/8, 2017 at 4:33 Comment(0)
C
7

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!

Compositor answered 15/4, 2020 at 18:24 Comment(0)
R
7

Use NVM to manage node version, it will automatically take care of npm.

Redmon answered 10/5, 2020 at 17:6 Comment(0)
T
7
npm install -g npm@latest

The above code can be run in the terminal to update your node package manager if you have already installed npm. If you don't have npm you can use

sudo apt-get install npm

then you can update it by the above method

Tavel answered 8/5, 2021 at 9:41 Comment(0)
M
7

NPM

As per the docs:

OSX & Linux

npm install -g npm@latest

Windows (in Powershell):

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade

NodeJS

Just download the installer from here: https://nodejs.org/en/

You can update NodeJS with NPM using npm install -g node but it isn't recommended.

Mudguard answered 23/10, 2021 at 8:14 Comment(0)
S
6

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.

Skinhead answered 19/8, 2016 at 13:17 Comment(0)
T
6

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.

Townley answered 26/7, 2017 at 7:4 Comment(0)
A
6

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.

Apery answered 13/10, 2017 at 16:27 Comment(0)
H
6

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.

Hoes answered 5/3, 2019 at 13:27 Comment(3)
@M.M it might possible that in your project, there is no package.json file. Please check that first.Hoes
You don't "need" to install npm-check-updates. This is merely a solution that uses a user made package.Isaacisaacs
@Isaacisaacs this is just one of the way to update the package. If other solutions won't work somehow, that time this solution may good for some.Hoes
M
5

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)
Montes answered 24/1, 2019 at 18:24 Comment(0)
S
5

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:-

https://nodejs.org/en/

enter image description here

and if you using linux then visit this stackoverflow question

https://mcmap.net/q/45703/-unable-to-install-nodejs-in-ubuntu-v-20-04-1

Scyphus answered 6/2, 2021 at 6:5 Comment(0)
G
5

If you are using the Windows operating system, please follow the instruction

  npm install npm@latest

If you are using ubuntu, you may also use the below command in your terminal

  sudo apt-get update
  sudo apt-get upgrade
  sudo npm install npm@latest

First, check your NPM version

 npm -v

View current NPM version:

npm view npm version

Update npm to the current version:

npm i -g npm

Happy coding, enjoy your life! Further, if you have face any difficulties let me know.

Ghastly answered 26/6, 2021 at 16:45 Comment(0)
N
4

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
Neoplasm answered 1/3, 2017 at 5:26 Comment(0)
E
4

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

Echeverria answered 14/5, 2017 at 5:21 Comment(0)
C
4

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/

Carmencarmena answered 3/10, 2017 at 17:40 Comment(1)
I'm running this command now. Does it take a long time? I've tried a few different solutions, even cleared my cache (On Windows 8.1) -- which someone later said not to do after I'd already done it -- so I'm hoping I can get this to work. Not sure if I will have to uninstall Node and reinstall....jeeshChanterelle
D
4

Any OS (including Windows, Mac & Linux)

Updated May 2021


Just go to the official Node.js site (nodejs.org), download and execute the installer program.

It will take care of everything and with a few clicks of 'Next' you'll get the latest Node.js version running on your machine. Since 2020 it's the recommended way to update NodeJS. It's the easiest and least frustrating solution.

Download NodeJS for Windows, buttons

Download NodeJS for Win/Mac/Source Code buttons


Pro tips

  • NodeJS installation includes NPM (Node package manager).

  • To check your NPM version use npm version or node --version.

  • If you prefer CLI, to update NPM use npm install -g npm and then npm install -g node.

    • For more details, see the docs for install command.
  • Keep an eye on NodeJS blog - Vulnerabilities so you don't miss important security releases. Keep your NodeJS up-to-date.

  • Operating systems supported by Node.js:

  • Troubleshooting for Windows:

    If anyone gets file error 2502/2503 like myself during install, run the .msi via Administrator command prompt with command msiexec /package [node msi]


If my answer is helpful, don't forget to upvote it
(here is the original answer by Anmol Saraf, upvote it too)

Decode answered 25/3, 2022 at 11:49 Comment(0)
T
3

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
Traprock answered 24/1, 2018 at 17:10 Comment(0)
E
3

Another way to do this on Ubuntu: use umake.

umake nodejs

installed the latest current version v11.14.0.

Plus:

  • update to latest version with just one command

Minus:

  • needs umake installed
Emeldaemelen answered 17/4, 2019 at 10:3 Comment(0)
A
3

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.

Agretha answered 13/5, 2019 at 10:48 Comment(0)
W
3

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
Walk answered 9/2, 2021 at 18:9 Comment(0)
I
3

Every time I install a new Linux OS, I need to install the nodejs and npm, and sometimes the stable distros installs an old version of these..

So, here are the steps to upgrade to the latest stable one...

$ sudo npm install -g n
$ sudo n stable # this is for stable one
$ sudo n latest # this is for latest one

Hope this will help :)

Inceptive answered 30/12, 2022 at 1:38 Comment(1)
shouldn't sudo s latest be sudo n latest?Poise
S
2

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.

Swain answered 26/3, 2019 at 13:38 Comment(3)
I'm on Windows 8.1. I did this and it didn't update npm. I previously had npm 6.10.x and after install of node 12.18.4 today, when I ran npm -v, it returned as 3.8.0. I've been trying to fix this ALL Day and now it appears after running npm i -g [email protected] I'm stuck at fetch -> lock |#####... for over 15min and counting.... this is so frustrating because I don't know what it is doing now.... and every time it gets stuck at a command for over 10-15 mins, I close the command window and start again.Chanterelle
When I ran 'npm install -g npm@latest', updates my NPM version perfectly fine. So I can't simulate you're situation here. Maybe reïnstalling NPM entirely helps you out? @ChanterelleSwain
thanks. I will just try to use the npm install -g npm@latest as you suggest and see what that does. If it doesn't work, I'll uninstall Node completely from my Win 8.1 laptop. I hope I don't have this issue on my Windows 10 desktop.Chanterelle
C
2

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

Collision answered 21/10, 2020 at 8:7 Comment(0)
F
1

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.

Furbelow answered 30/3, 2017 at 18:35 Comment(0)
S
1

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.

  1. Go to nodejs.org
  2. Then click "other downloads" of the desired version.
  3. Search for "Installing Node.js via package manager"
  4. Click on your os type. Example "Debian and Ubuntu based Linux distributions"
  5. Do what ever written. Basically need to run two command only.

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.

Spirited answered 1/7, 2018 at 5:38 Comment(1)
I am running devWL's solution, the command is taking a long time (appears to be hung at fetch -> lock ... command) if it doesn't move after another 5 min, I'm closing the command prompt. I've been trying to rectify this upgrade issue for over 12 hours (no lie -- I left the computer running and it was just appeared to be stuck). It's ridiculous.Chanterelle
J
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?

Jerold answered 12/10, 2018 at 13:36 Comment(2)
So should we always install Node as Admin on Windows machines? (I'm on Win 8.1). I'm seeing that npm installs itself either in ProgramFiles or in user path directory without rhyme or reason. This installation should be more consistent or maybe someone can explain why npm installs itself in different places??? I don't remember installing Node as Admin --but maybe at some point I did? (but I KNOW I didn't use Powershell)...Chanterelle
@Chanterelle I never tried to install it as a non admin. I always Install the nodejs package from chocolatey. Whether powershell or cmd is used won't make a difference to node once it is installed.Jerold
H
1

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

Hypostyle answered 4/10, 2020 at 12:38 Comment(0)
H
1

Use nvm if you want to learn more about

Nvm Nvm windows

For windows,installation follow this step by step installtion

Hedley answered 21/7, 2021 at 9:7 Comment(1)
Please avoid link only answers. Answers that are "barely more than a link to an external site” may be deleted.Electrothermics
I
1

Steps to Upgrade npm and node Latest versions
1)Start by updating the package repository with the command

sudo apt update

2)Install NVM using the curl command

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

3)Close and reopen the terminal for system to recognize the changes or run the command:

source ~/.bashrc

4)Then, verify if you have successfully installed NVM:

nvm --version

5)Before upgrading Node.js, check which version you have running on the system:

nvm ls-remote

v14.17.0 (LTS: Fermium) v14.17.1 (LTS: Fermium) v14.17.2 (LTS: Fermium) v14.17.3 (LTS: Fermium) v14.17.4 (LTS: Fermium) v14.17.5 (LTS: Fermium) v14.17.6 (LTS: Fermium) v14.18.0 (Latest LTS: Fermium)

6)To install the latest version, use the nvm command with the specific Node.js version: My Latest Version

nvm install [version.number]
nvm install [14.8.0]

Node Updated Screenshot

Immense answered 4/10, 2021 at 13:1 Comment(0)
D
1

my advice is to use nvm (node version manager) which will allow you to install several versions of node and npm at the same time and will facilitate updates of node to LTS versions but also on Linux nvm overlay all npm command to avoid typing sudo for packages requiring superuser privileges. This is the link to see more about how nvm works.

Deafening answered 17/5, 2022 at 21:46 Comment(0)
I
1

For windows
After installed the Node.js v16.15.1
npm -v is still 6.6.0
delete npm and npm-cache under C:\Users\neals\AppData\Roaming
npm -v is 8.11.0

Itinerary answered 5/9, 2022 at 2:48 Comment(0)
M
1

Node :

Don't worry about the current node version which is installed already. Just download and install the latest version from https://nodejs.org/en and run the installation wizard. (Note: The installation takes care of removing the existing node version and updates to the latest! )

You can verify the updated version by running:

node -v

enter image description here

NPM : (without NVM)

To upgrade npm to the latest version on Windows, you can use the following command in the Command Prompt or PowerShell:

npm install -g npm@latest

After running the command, npm will download and install the latest version. Once the installation is complete, you can verify the updated version by running:

npm --version

Hope this helps! enter image description here

Myna answered 20/6, 2023 at 9:16 Comment(2)
"Don't worry about the current node version which is installed already" — Do worry. Having different versions of node installed on different paths is a pain.Electrothermics
@Electrothermics by default Node installer uses previously installed directory, unless changed manually.Totten
T
1

Steps to follow to update node and/or npm if you have them already installed on windows:

For NODE:

  1. check current Node version by node -v command
  2. Download the preferred later version of node. From: https://nodejs.org/en/download/
  3. Install it in the exact same directory as existing node (Ideally, should not require manual intervention) , this will remove the need for resetting system path variables.
  4. Confirm with node -v

For NPM :

  1. Run the command npm install -g npm@latest (for stable version) or npm install -g npm@next (for recent version)
  2. Confirm with npm -v

NOTE: If node version is lower than 18.17.0, step 5 will throw error on windows.

error log

Totten answered 24/12, 2023 at 17:1 Comment(0)
S
0

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

Showdown answered 12/4, 2018 at 11:32 Comment(1)
@reectrix : Let me know the scenario, so that I can be more specific about it, and improve the answer.Showdown
U
0

We can update specific version of npm in the following way

npm install -g [email protected] 
Ullrich answered 2/9, 2022 at 16:2 Comment(0)
R
0

If you use linux you can use nvm to to manage multiple node versions in you projects

NVM allow you to install and use different versions in your project simple by:

  • nvm install YOUR_VERSION to install your version
  • nvm use YOUR_VERSION in your project to the version in the project also you can use .nvmrc file to manage automatically the version in your projects

To install Nvm you can use the official documentation Or by executing the next commands

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Now you are ready to use nvm....

Reinhardt answered 10/10, 2022 at 20:46 Comment(0)
D
0

Use these commands to upgrade your node and npm to the latest version

First, uninstall the npm

npm uninstall -g npm

then clear the npm cache

npm cache clean --force

then install it again

npm install -g npm@latest

Hope it works!

Daudet answered 2/2 at 15:25 Comment(0)
E
-1

Update node latest version with this command:

nvm install <version>
Emulsion answered 13/2, 2023 at 11:30 Comment(2)
All else being equal, this will throw an error because nvm isn't installed.Electrothermics
in that condition first you have to install nvm.Emulsion

© 2022 - 2024 — McMap. All rights reserved.