I just had a trouble to upgrade my npm version from 5.0.0 to 6.4.1 on Windows 10.
What i did was just downloading NodeJS (latest) installer, i.e. 8.12.0 (it includes npm 6.4.1). It was successfully installed, however when i did npm -v it still on version 5.0.0, so it only updated the node part only.
Then i follow this instruction (link), basically it uses npm package called npm-windows-upgrade, at first try it threw a lot of error.
Basically i have to do several cycles of NodeJS uninstall, NodeJS reinstall, and executing npm-windows-upgrade, after few times it finally succeeded (luck), now my npm is at 6.4.1. However when i run where npm on terminal it listed two locations of my npm files:
C:\WINDOWS\system32>where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
C:\Users\XXX\AppData\Roaming\npm\npm
C:\Users\XXX\AppData\Roaming\npm\npm.cmd
and this is kind of strange, it should only listing one location, i.e. C:\Program Files\nodejs\.. but apparently i have npm too on AppData\Roaming directory, why is this happening? should i delete the second one?
PS - If i run where node, it listed only one location, i.e:
C:\WINDOWS\system32>where node
C:\Program Files\nodejs\node.exe
C:\Users\xxx\AppData\Roaming\npm is the location for node packages for the current user, while C:\Program Files\nodejs\ is the installation dir for all users.
See what C:\Users\XXX\AppData\Roaming\npm\npm.cmd -v returns. If it's the same as npm -v then you are fine.
You could run node without the installer, in this case C:\Program Files\nodejs\ would not be in the PATH (for System env variables), however all the global packages would be placed under C:\Users\XXX\AppData\Roaming\npm\. Since npm is a global package, it appers there.
TL;DR No action required.
Related
It is my understanding that npm gets installed alongside node when I use the node installer in Windows 10, and will be located in "D:\Program Files (x86)\nodejs" (I installed the 32 bit version to my D drive, C is my primary OS drive).
However, "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)." - https://docs.npmjs.com/try-the-latest-stable-version-of-npm
Initially, after I first installed nodejs, my Roaming/npm folder was empty since I did not install any packages globally. Afterwards, I wanted to upgrade my npm so I ran the following command - "npm i -g npm". This added the following items to my Roaming/npm folder.
Roaming/npm
Now, when I run npm -v, the updated version is shown (7.24.2).
My questions are:
1.) Since I only updated the global ( -g ) installed one ( %appdata%\npm\ ), the npm in "D:\Program Files (x86)\nodejs" should remain as the old version right? (6.4.13).
2.) If so, why is the newer version being used, if (refer to below)
According to https://docs.npmjs.com/try-the-latest-stable-version-of-npm, "it will always use the version of npm installed with node instead of the version of npm you installed using npm -g install npm#." This does not seem like the case for me.
I did a "echo %PATH%" in cmd and I have confirmed that "D:\Program Files (x86)\nodejs" is indeed placed before "C:\Users<username>\AppData\Roaming\npm". So why is the newer version being used instead?
I tried to open cmd in "D:\Program Files (x86)\nodejs" and ran ".\npm.cmd -v" and it still gave me the same result which I was not expecting (7.24.2). I looked at the date modified for the nodejs folder and it does not seem like any changes were made.
Another thing I tried was logging in as a different user on my PC and running "npm -v", when I did that, it was showing the old version (which is what I expected since npm was only updated for my admin account, (admin\Appdata\Roaming\npm). So why is it that when I'm logged in as admin, it seems like the npm in "D:\Program Files (x86)\nodejs" is updated as well?
Any help to enhance/correct my understanding would be greatly appreciated, I am still quite new to npm and node.
Update: I am aware that nvm exists. This question is asking about the behaviour mentioned above.
Every time I try to run npm on Windows 10, I get Error: EINVAL: invalid argument, mkdir 'C:\Program Files\nodejs"'
I have deleted %Appdata%\npm and %Appdata%\npm-cache.
I have deleted c:\program files\nodejs, checked that c:\program files (x86)\nodejs does not exist, and tried to install NodeJS in c:\nodejs instead to get rid of the space in the directory name.
I have uninstalled NodeJS and searched through the Windows registry, removing every reference to NodeJS.
I have tried to use NPM to update NPM to a different version, but I only get the same error.
I have removed all references to Node folders from environment variables and paths.
Of NodeJS versions I have tried Latest LTS Version: 12.16.3 (includes npm 6.14.4), and Latest Current Version: 14.2.0 (includes npm 6.14.4).
I have tried using Chocolatey to install NodeJS, it made no difference.
Every time I reboot, reinstall NodeJS, and try to use NPM, I get the same error.
When I try to check what version of NPM is actually installed, the answer is ... the same error.
How do I eradicate all NodeJS and NPM related files and settings from Windows 10 so that I can perform an actual clean install, without having to resort to the nuclear option, formatting the drive and reinstalling Windows?
Ok, after ripping my hair out, as well as half of the installed software on my PC, I continued googling, and eventually stumbled on the solution by investigating some file paths mentioned in this question: nodejs npm global config missing on windows.
Apparently, there is a config file %userprofile%\.npmrc which is relevant somehow. On my own computer, this file contained the text prefix=C:\Program Files\nodejs".
If that looks familiar, it's because it's the string in the error message that has been plaguing me. When I emptied the file, npm started working again, just like that.
I'm unable to update npm, and get it to use with Nodist.
Whenever I try to update npm with the command
npm install -g npm
the following message comes right after executing it:
(node:5304) fs: re-evaluating native module sources is not supported.
If you are using the graceful-fs module, please update it to a more recent version.
C:\Program Files (x86)\Nodist\v\nodev6.5.0\npm -> C:\Program Files (x86)\Nodist\v\nodev6.5.0\node_modules\npm\bin\npm-cli.js
npm#3.10.6 C:\Program Files (x86)\Nodist\v\nodev6.5.0\node_modules\npm
Doing an npm -v right after, gives me the previous version:
...> npm -v
2.14.10
However, if you noticed the last line in the message above, there is npm#3.10.6 which means it is somehow trying to install that version of npm.
I also followed instructions from this post for Ubuntu users and this for Windows users, but they seem to address issues with standalone NodeJS installations and NOT NodeJS + Nodist combo.
Meanwhile, I was wondering if Nodist itself enables us to update npm, or in other words, does it have any version management feature for npm as well, just as it does for node.
Thanks for any help in advance.
Additional Info
I am using Nodist v0.7.1 on Windows 7.
You can try nodist npm latest
Nodist manages npm versions as well as node versions.
Turns out that Nodist versions prior to v0.7.2 have an issue with getting npm set with Nodist correctly (refer the Nodist changelog).
Performing an npm install -g npm was in fact installing the latest version of npm under the v-x64 in Nodist's root installation folder - which is not where Nodist itself looks for npm installation.
Nodist looks for npm inside the \bin folder:
Solution
Add the bin folder's path to your PATH.
cd to the Nodist installation > bin directory with your terminal,
and then perform:
npm install npm
(not with -g flag of course).
Alternatively, if npm install doesn't work in this step, copy an already installed npm and paste it in the node_modules folder within the bin directory.
As a side note, remember to remove some values from your PATH which I suppose may cause conflicts with global package installations (i.e. with -g flag) with npm, before installing Nodist, which are as follows:
%appdata%\npm; OR C:\Users\username\AppData\Roaming\npm;
%ProgramFiles%\nodejs;
I used to have the same issue.
You should use the following command nodist npm 6.14.5, changing the version you need.
And you can see more option whith this command: nodist --help is where I found the answer:
see an example
I'm running windows 7 and when I installed node.js, it came with NPM 1.4.3. I need NPM 2.0.2 so I ran the following;
C:\proj>npm install -g npm#2.0.2
npm http GET http://localhost:8000/nexus/content/groups/npm-all/npm/2.0.2
npm http 200 http://localhost:8000/nexus/content/groups/npm-all/npm/2.0.2
npm http GET http://localhost:8000/nexus/content/groups/npm-all/npm/-/npm-2.0.2.tgz
npm http 200 http://localhost:8000/nexus/content/groups/npm-all/npm/-/npm-2.0.2.tgz
C:\Users\pgreen\AppData\Roaming\npm\npm -> C:\Users\pgreen\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm#2.0.2 C:\Users\pgreen\AppData\Roaming\npm\node_modules\npm
The output does show that I'm using a local nexus plugin to do NPM Repository proxy, but I have no reason to suspect that is causing any problems.
After the install I see:
C:\proj>npm --version
1.4.3
So what am I missing to make npm version 2.0.2 available on the command line?
I just needed to RTFM:
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\\AppData\Roaming\npm). Because the installer puts
C:\Program Files (x86)\nodejs before
C:\Users\\AppData\Roaming\npm on your PATH, it will always
use version of npm installed with node instead of the version of npm
you installed using npm -g install npm#. To get around this,
you can do one of the following:
Option 1: edit your Windows installation's PATH to put C:\Users\<username>\AppData\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
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
If you installed npm with the node.js installer, after doing one of
the previous steps go into C:\Program Files\nodejs\node_modules\npm
and copy the file named npmrc in the new npm folder, which should be
C:\Users\\AppData\Roaming\npm\node_modules\npm. This will
tell the new npm where the global installed packages are. See the
point below for more details.
(See also the point below if you're running Windows 7 and don't have
the directory C:\Users\\AppData\Roaming\npm.)
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;
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
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.
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!
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.
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