6

I'm trying to update npm to latest version, since I'm using the 1.4.28. Using:

npm update -g npm

I get the following output:

npm@1.3.26 C:\Users\ck\AppData\Roaming\npm\node_modules\npm-check-updates\node_modules\npm
npm@2.1.5 C:\Users\ck\AppData\Roaming\npm\node_modules\ember-cli\node_modules\npm

and then running

npm -v

I can see that I'm still using the 1.4.28; I can't understand the output I got after trying to update, since it is talking about 1.3.26 and 2.1.5, but I have installed 1.4.28??

I'm on windows and I've already tried to uninstall and reinstall node;

Cereal Killer
  • 3,387
  • 10
  • 48
  • 80
  • The `npm` installations you're updated are dependencies of other modules -- `npm-check-updates` and `ember-cli`. Those modules will likely have limitations on what versions of `npm` they support. – Jonathan Lonowski Oct 19 '14 at 17:20
  • ok, thanks fro clarifing this; but why npm update -g npm does not update the version I'm using from 1.4.28 to 2.1.0? And from where it comes from version 1.4.28? – Cereal Killer Oct 19 '14 at 17:21
  • 1
    For Windows, `npm` typically isn't placed under the global [`root`](https://www.npmjs.org/doc/cli/npm-root.html) where it can manage itself. It's usually under `Program Files` instead. You can check this with `npm -g root` and `gcm npm | select source` (PowerShell). – Jonathan Lonowski Oct 19 '14 at 17:32
  • Thanks this solved the issue: npm (1.4.28) was installed in c:\programs\nodejs while the npm root was somewhere else – Cereal Killer Oct 19 '14 at 18:06
  • So, how did you actually update npm? I'm in that same situation where updating npm or re-installing node leaves me at 1.4.28; my npm root is "C:\Windows\system32\node_modules" and my npm -g root is "C:\Users\\AppData\Roaming\npm\node_modules", but I'm not clear on what to do with that info. – Wayne Nov 06 '14 at 21:34

5 Answers5

11

from this page:https://github.com/npm/npm/wiki/Troubleshooting

on windows:
            Option 1:
              edit your Windows installation's PATH to put C:\Users\<username>\AppDa\Roaming\npm before
     C:\Program Files (x86)\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 before updating
                C:\Program Files (x86)\nodejs\npm
                C:\Program Files (x86)\nodejs\npm.cmd

            Option 3: navigate to C:\Program Files (x86)\nodejs 
               with cmd.exe and then run the installation without -g:
               npm install npm

on linux:
npm install -g npm@latest
baaroz
  • 19,119
  • 7
  • 37
  • 47
2

In order to install the latest npm, you'll run:

npm install -g npm@latest

You'll also need to ensure that if you have multiple npm commands installed, you are using the latest (rather than the original npm installed with node).

Try this:

which -a npm

Based on your findings from the above command, you may need to adjust your PATH environment variable.

Wil Moore III
  • 6,968
  • 3
  • 36
  • 49
  • This is very confusing, does it nest an installation of npm within npm, or does it really globally update the installation of npm in the OS? Anyway, I get `/usr/local/lib/iojs-v3.3.1-linux-x64/bin/npm -> /usr/local/lib/iojs-v3.3.1-linux-x64/lib/node_modules/npm/bin/npm-cli.js npm@2.14.3 /usr/local/lib/iojs-v3.3.1-linux-x64/lib/node_modules/npm `. Maybe it doesn't play well with having io.js installed and upgraded. Is it only me? :) – matanster Sep 16 '15 at 11:44
  • Do you have /usr/local/lib/iojs-v3.3.1-linux-x64/bin in your `$PATH`? – Wil Moore III Sep 17 '15 at 08:28
  • Nope. [I posted a separate question for it](http://stackoverflow.com/questions/32607923/is-io-js-hijacking-npms-global) – matanster Sep 17 '15 at 10:26
1

Finally able to update npm. A bit uncooperative guy whew! Tried to install / update nom first npm install -g nom@latest then npm install -g npm@latest on admin level console / windows command.

From 1.4.28 to 2.1.7

Weird but hey it works for me!

Graham P Heath
  • 7,009
  • 3
  • 31
  • 45
  • Is the first install -g *nom*@latest intentional, or a typo. Seems like nom is really a thing, a jquery implementation for the server-side, but i doubt you meant that here. – Graham P Heath Jan 17 '15 at 16:07
1

On Windows, you may need to check both your user path and system path. If C:\Program Files\nodejs\; appears in system path and C:\Users\<username>\AppData\Roaming\npm, then npm will refer to the version in C:\Program Files\nodejs\;. This was the problem for me, and was resolved by putting C:\Program Files\nodejs\; at the end of the user path and removing it from the system path. Don't forget to restart the terminal after changing the path. Though useful in helping me to find the problem, none of baaroz's solutions worked in my case.

Tom
  • 7,994
  • 8
  • 45
  • 62
0

I deleted this folder C:\Users<username>\AppDa\Roaming\npm and C:\Users<username>\AppDa\Roaming\npm-cache and the did the node.js install and was able to have the updated version of npm

Juan
  • 1,352
  • 13
  • 20