Fixing npm path in Windows 8 and 10

前端 未结 18 1605
孤街浪徒
孤街浪徒 2020-11-22 15:30

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          


        
相关标签:
18条回答
  • 2020-11-22 15:35

    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

    0 讨论(0)
  • 2020-11-22 15:37

    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

    0 讨论(0)
  • 2020-11-22 15:39

    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

    0 讨论(0)
  • 2020-11-22 15:40

    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.

    0 讨论(0)
  • 2020-11-22 15:40

    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.

    0 讨论(0)
  • 2020-11-22 15:40

    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
    
    0 讨论(0)
提交回复
热议问题