Fixing npm path in Windows 8 and 10
Asked Answered
V

22

181

Have done a lot of googling, tried reinstalling node.js using the official installer, but my npm pathing still doesn't work.

This doesn't work

npm install foo

I get an error message saying missing module npm-cli.js

2 hours of googling later I discovered a workaround
Instead of simply 'npm' I type

node C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js

But how can I correct my nodejs install so I can simply type 'npm' ?

Vermicular answered 9/1, 2015 at 15:36 Comment(2)
You need to add `C:\Program Files\nodejs\node_modules\npm\bin` to your PATH.Aegaeon
At first please check` npm --v` for that it shows the verssion or not.Degradation
P
265

You need to Add C:\Program Files\nodejs to your PATH environment variable. To do this follow these steps:

  1. Use the global Search Charm to search "Environment Variables"
  2. Click "Edit system environment variables"
  3. Click "Environment Variables" in the dialog.
  4. In the "System Variables" box, search for Path and edit it to include C:\Program Files\nodejs. Make sure it is separated from any other paths by a ;.

You will have to restart any currently-opened command prompts before it will take effect.

Psychiatrist answered 9/1, 2015 at 15:48 Comment(7)
thanks will try, Is it necessary to reboot for the changes to have effect?Vermicular
I assume this SHOULD work, but I now get 'Error : Cannot find module 'npmlog'Vermicular
Try changing the path C:\Program Files\nodejs\node_modules\npm\bin to C:\Program Files\nodejsPsychiatrist
In my case autocomplete was not working, but node and npm worked.Allhallowtide
Where does VS 2017 install nodejs, I'm unable to find it.Thiel
Tried 20+ accepted answers in last 4 days. Nothing works for me. process.env.ANY_VARIABLE always gives undefinedHealion
@VipulHadiya I'm not sure your issue is related to a the original question, it seems more a node/project configuration issue.Psychiatrist
J
193

get the path from npm:

npm config get prefix

and just as a future reference, this is the path I added in Windows 10:

C:\Users\{yourName}\AppData\Roaming\npm



Update:

If you want to add it for all users just add the following path [by @glenn-lawrence from the comments]:

%AppData%\npm

Jactitation answered 22/8, 2015 at 18:6 Comment(5)
Exactly this! For some reason my PATH lost that folder, the npm was working and installing apps such as uglify-js was properly done, but they were not showing up in any terminal. I just did what you wrote, added that folder to PATH and Sublime Text can now read those apps. Appreciated.Beekman
On Windows 8 and 10 you can just use %AppData%\npm to make it work for any user.Globigerina
If you're landing here from a search, you're most likely looking for this.Sweat
on my Windows 10 Home laptop: I used Glenn's solution, but for some weird reason had to move %APPDATA%\npm to be high up in the list of entries for PATH. on other computers I did not have to do that ...Seamount
The developer's life is definitely harder on Windows. This tip is really useful.Ampere
M
20

I have used the cmdlet and navigate to the path you want to switch your npm files to. Type in npm root -g to see what the current path your npm is installed to. Next use npm config set prefix and your npm path will be changed to whatever directory you are currently on.

Mountain answered 27/7, 2017 at 1:34 Comment(1)
I agree with Mr Z. Khullah, no one solutions was worked for me, accept the solution provided by Mr Martez C. environment/os windows 10 home with multi-users.Gershom
R
10

Try this one dude if you're using windows:

1.) Search environment variables at your start menu's search box.
2.) Click it then go to Environment Variables...
3.) Click PATH, click Edit
4.) Click New and try to copy and paste this: C:\Program Files\nodejs\node_modules\npm\bin

If you got an error. Do the number 4.) Click New, then browse the bin folder

  • You may also Visit this link for more info.
Relator answered 28/10, 2016 at 12:20 Comment(0)
A
9

Go to control panel -> System -> Advanced System Settings then environment variables.

From here find the path variable, Go to the end of the line and paste "C:\Program Files\nodejs\node_modules\npm\bin" (change the path to the directory to where ever you installed it e.g. if you specifically installed it anywhere change it)

Adz answered 9/1, 2015 at 15:52 Comment(0)
N
9

Edit the System environment variables, and enter following path:

C:\Program Files\nodejs\node.exe;

C:\Users\{yourName}\AppData\Roaming\npm

Nmr answered 25/7, 2019 at 2:50 Comment(0)
K
7

Installed Node Version Manager (NVM) for Windows: https://github.com/coreybutler/nvm-windows

I'm using Windows 10 - 64 bit so I run... Commands:

  • nvm arch 64 (to make default the 64 bit executable)
  • nvm list (to list all available node versions)
  • nvm install 8.0.0 (to download node version 8.0.0 - you can pick any)
  • nvm use 8.0.0 (to use that specific version)

In my case I had to just switch to version 8.5.0 and then switch back again to 8.0.0 and it was fixed. Apparently NVM sets the PATH variables whenever you do that switch.

Kennel answered 22/9, 2017 at 14:29 Comment(1)
I forget to turn on nvm. So I have to execute "nvm on" command. This is for first time installation.Grippe
D
6

You can follow the following steps:

  • Search environment variables from start menu's search box.
  • Click it then go to Environment Variables
  • Click PATH
  • click Edit
  • Click New and try to copy and paste your path for 'bin' folder [find where you installed the node] for example according to my machine 'C:\Program Files\nodejs\node_modules\npm\bin'

If you got any error. try the another step:

  • Click New, then browse for the 'bin' folder
Degradation answered 6/1, 2020 at 9:31 Comment(2)
It was helpful for me.Kerf
It is my pleasure.Degradation
S
5

I did this in Windows 10,

  1. Search for Environment Variables in the Windows search
  2. "Edit the System environment variables" option will be popped in the result
  3. Open that, select the "Path" and click on edit, then click "New" add your nodeJS Bin path i.e in my machine its installed in c:\programfiles\nodejs\node_modules\npm\bin
  4. Once you added click "Ok" then close

Now you can write your command in prompt or powershell.

If you using WIndows 10, go for powershell its a rich UI

Spiry answered 1/4, 2019 at 6:16 Comment(0)
M
5

If after installing your npm successfully, and you want to install VueJS then this is what you should do

after running the following command (as Admin)

npm install --global vue-cli

It will place the vue.cmd in the following directory C:\Users\YourUserName\AppData\Roaming\npm

you will see this in your directory.

Now to use vue as a command in cmd. Open the cmd as admin and run the following command.

setx /M path "%path%;%appdata%\npm"

Now restart the cmd and run the vue again. It should work just fine, and then you can begin to develop with VueJS.

I hope this helps.

Missie answered 19/12, 2019 at 22:30 Comment(0)
N
4

This worked for me: 1. npm root -g (to see the current npm is installed) 2. npm config set prefix (to change the path)

Niko answered 19/12, 2017 at 9:11 Comment(0)
G
2

change the path for nodejs in environment varibale.

setting environment variable

Gunplay answered 21/10, 2018 at 2:21 Comment(0)
J
1

add Environment Path to

C:\Program Files\nodejs\node.exe;C:\Users[your username]\AppData\Roaming\npm

Jacobs answered 15/4, 2019 at 11:1 Comment(0)
B
1

steps 1 in the user variable and system variable

  C:\Program Files\nodejs

then check both node -v and the npm -v then try to update the the npm i -g npm

Baronet answered 9/3, 2020 at 10:19 Comment(0)
A
1

The problem for me was a Zscaler certificate issue. I reached out to the IT team and they gave me a Zscaler certificate with a .pem extension to use.

Then you can run this line

npm config set cafile <Path to Certificate>/<certificate name>.pem
Artificial answered 6/6, 2023 at 15:7 Comment(0)
J
0

I've had this issue in 2 computers in my house using Windows 10 each. The problem began when i had to change few Environmental variables for projects that I've been working on Visual studio 2017 etc. After few months coming back to using node js and npm I had this issue again and non of the solutions above helped. I saw Sean's comment on Yar's solution and i mixed both solutions: 1) at the environmental variables window i had one extra variable that held this value: %APPDATA%\npm. I deleted it and the problem dissapeared!

Jewelljewelle answered 20/2, 2018 at 18:58 Comment(0)
D
0

If you can't work with npm packages, you propably has bad config with npm install packages, you try this:

Run the following command in your terminal to revert back to the default registry

npm config set registry https://registry.npmjs.org/

https://docs.npmjs.com/misc/config#registry

Delozier answered 13/10, 2019 at 13:50 Comment(0)
D
0

When you're on Windows but running VS Code in Windows Subsystem for Linux like this

linux@user: /home$ code .

you actually want to install NodeJs on Linux with

linux@user: /home$ sudo apt install nodejs

Installing NodeJs on Windows, modifying PATH and restarting will get you no results.

Deiform answered 22/4, 2020 at 19:49 Comment(0)
C
0

If, like me, you have MSYS_NO_PATHCONV = 1 configured as a user variable for Git Bash, this issue will be triggered. To workaround, you can either remove this variable or use a different shell (PowerShell) for npm.

Cressida answered 16/2, 2021 at 9:35 Comment(0)
G
0

I did Node repair with the .msi file and everything worked well.

Gleason answered 24/4, 2021 at 13:19 Comment(0)
W
0

I tried to update the environment variables to "C:\Program Files\nodejs". It did nothing for me.

  • Open Command Prompt.
  • Execute the following command "npm config edit"
  • Search "prefix" and remove the semicolon before the prefix.
  • Put the path to nodejs folder location(Eg: C:\Program Files\nodejs).
  • Save and exit the file.
Waw answered 10/7, 2023 at 20:45 Comment(0)
M
-3

I may be a total noob but I had no clue I had to install npm-cli first. I had just assumed I already had it.

npm install --global vue-cli
Michalmichalak answered 11/7, 2019 at 2:58 Comment(2)
The answer you've mentioned refers to npm-cli, but your snippet refers to vue-cli. Which one do you intend to use?Corroboree
It make no sense to do this :(Patiencepatient

© 2022 - 2024 — McMap. All rights reserved.