Installing Node.js (and npm) on Windows 10

240,660

Solution 1

Edit: It seems like new installers do not have this problem anymore, see this answer by Parag Meshram as my answer is likely obsolete now.

Original answer:

Follow these steps, closely:

  • http://nodejs.org/download/ download the 64 bits version, 32 is for hipsters
  • Install it anywhere you want, by default: C:\Program Files\nodejs
  • Control Panel -> System -> Advanced system settings -> Environment Variables
  • Select PATH and choose to edit it.

If the PATH variable is empty, change it to this: C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs

If the PATH variable already contains C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm, append the following right after: ;C:\Program Files\nodejs

If the PATH variable contains information, but nothing regarding npm, append this to the end of the PATH: ;C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs

Now that the PATH variable is set correctly, you will still encounter errors. Manually go into the AppData directory and you will find that there is no npm directory inside Roaming. Manually create this directory.

Re-start the command prompt and npm will now work.

Solution 2

go to http://nodejs.org/

and hit the button that says "Download For ..."

This'll download the .msi (or .pkg for mac) which will do all the installation and paths for you, unlike the selected answer.

Solution 3

In addition to the answer from @StephanBijzitter I would use the following PATH variables instead:

%appdata%\npm
%ProgramFiles%\nodejs

So your new PATH would look like:

[existing stuff];%appdata%\npm;%ProgramFiles%\nodejs

This has the advantage of neiter being user dependent nor 32/64bit dependent.

Solution 4

New installers (.msi downloaded from https://nodejs.org) have "Add to PATH" option. By default it is selected. Make sure that you leave it checked.

Add to PATH

Solution 5

Everything should be installed in %appdata% (C:\Users\\AppData\Roaming), not 'program files'.

Here's why...

The default MSI installer puts Node and the NPM that comes with it in 'program files' and adds this to the system path, but it sets the user path for NPM to %appdata% (c:\users[username]\appdata\roaming) since the user doesn't have sufficient priveleges to write to 'program files'.

This creates a mess as all modules go into %appdata%, and when you upgrade NPM itself - which NPM themselves recommend you do right away - you end up with two copies: the original still in 'program files' since NPM can't erase that, and the new one inn %appdata%.

Even worse, if you mistakenly perform NPM operations as admin (much easier on Windows then on *nix) then it will operate on the 'program files' copy of NPM node_modules. Potentially a real mess.

So, when you run the installer simply point it to %appdata% and avoid all this.

And note that this isn't anything wierd - it’s what would happen if you ran the installer with just user priveleges.

Share:
240,660
Stephan Bijzitter
Author by

Stephan Bijzitter

Updated on July 05, 2022

Comments

  • Stephan Bijzitter
    Stephan Bijzitter almost 2 years

    I had some issues trying to install Node on Windows 10 and found the solution.

    The error was as follows:

    C:\Users\Stephan>npm
    Error: ENOENT, stat 'C:\Users\Stephan\AppData\Roaming\npm'

    The solution is below.

  • Stephan Bijzitter
    Stephan Bijzitter about 9 years
    @captainrad so far I have not had any trouble, but I cannot be sure about release before Dec 7
  • onuralp
    onuralp about 9 years
    @captainrad It worked when I copied files in C:\Program Files\nodejs to C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm on Windows 10
  • Stephan Bijzitter
    Stephan Bijzitter over 8 years
    Mind explaining why the accepted answer did not work for you?
  • Shai UI
    Shai UI over 8 years
    The accepted answer required me to manually enter the paths which is not required if you run the installer (.msi).
  • Stephan Bijzitter
    Stephan Bijzitter over 8 years
    Then either the installer has been updated to automatically do this in the past few weeks, or you just got lucky on your system :-) I do doubt this, however.
  • Scott Stensland
    Scott Stensland over 8 years
    This is the correct answer. If you are on Windows the default install works ( .msi ) ... thanks @foreyez
  • Stephan Bijzitter
    Stephan Bijzitter over 8 years
    @DannyG Thanks for your edit, but please only edit when it improves the answer. Refer to stackoverflow.com/help/editing for more on this subject.
  • Kendra
    Kendra over 8 years
    Just as a heads up, Stephan, the recent edit/rollback sparked a (not bad) Meta conversation it might be worth your time to look at. It might give you some more context for why DannyG edited your answer.
  • munkee
    munkee over 8 years
    Definitely the best answer - works fine on windows 10 for me too
  • ddagsan
    ddagsan almost 8 years
    I tried to reinstall and it's working now. Path must be in "User variables for {user login name}" listbox, not system variables.
  • crishushu
    crishushu over 7 years
    "... is for hipsters" ;-)
  • Dave Morton
    Dave Morton over 7 years
    This is great if you've installed it in the default location, but please bear in mind that if you did not, this will only serve to clutter up the PATH variable.
  • Stephan Bijzitter
    Stephan Bijzitter about 7 years
    Well finally :-)
  • DerpyNerd
    DerpyNerd over 6 years
    October 2017, this answer still applies but the npm folder in Roaming was created in my case but contains no files
  • DerpyNerd
    DerpyNerd over 6 years
    Strange, I used this installer and they were definitely checked. I still had to add the nodejs folder in the path variables
  • Tom
    Tom over 6 years
    That sounds sensible but ends up creating a mess (if you do this as admin). I explain in my answer below why you should tell the installer to put it in %appdata% instead.
  • shivgre
    shivgre over 6 years
    This should be marked as correct answer as Its just one step solution rather then @StephanBijzitter solution which requires me to first browse their download directory searching for correct versions which I don't know about(not familiar with nodejs).
  • M. Doosti Lakhani
    M. Doosti Lakhani over 4 years
    The installer does not work on Windows 10 at all. It only creates a path to installation folder not roaming.