Node: Windows

Installing and working with Node, npm, nvm on Windows

There are various methods of using Node on Windows:

Windows (via Command Prompt)

This method is the simplest to setup, but restricts you to using Node in the Windows Command Prompt.

To install Node for the Windows Command Prompt, download an installer from https://nodejs.org/en/download/.

After installing Node, open Command Prompt and run node -v and npm -v to verify that the version numbers for Node and npm match the installer that you downloaded.

You should now be able to open a Command Prompt window and run node and npm commands as usual.

Keep in mind that Command Prompt does not support most UNIX commands. As a result, Node scripts that utilize system commands (like the setup script in demo-nextjs-app) will not run properly. Because of this, we strongly discourage this method and recommend one of the other methods.

Windows (via Git Bash)

This method requires you to install one additional program, but gives you the ability to use Node in a UNIX-like environment with access to a limited number of UNIX commands.

First, install Node using the same method as above (by downloading and running the installer).

Then, download and install Git for Windows from https://git-scm.com/downloads.

When running the installer, we recommend the following options:

After installing both Node and Git, open Git Bash and run node -v and npm -v to verify that the version numbers for Node and npm match the installer that you downloaded.

You should now be able to open a Git Bash window and run node, npm, and basic UNIX commands as usual.

Windows Subsystem for Linux (WSL)

For users who are looking to use Node with packages installed from package managers (such as apt-get for Ubuntu/Debian) and use the full suite of UNIX commands, we recommend using Windows Subsystem for Linux (WSL).

First, install WSL using the instructions here: Windows: WSL. This guide assumes that you have installed a Debian-based Linux distribution (like Ubuntu).

Next, remove all previous versions of Node that you may have installed in WSL by running this command:

sudo apt-get purge --auto-remove nodejs

(Source: https://askubuntu.com/questions/786015/how-to-remove-nodejs-from-ubuntu-16-04)

Visit the NodeSource Node.js Binary Distributions page, navigate to “Installation and Instructions” under “Debian and Ubuntu based distributions”, and run the commands listed for your desired Node version. This will install the requested version of Node and npm.

After installing, run node -v and npm -v to verify that the version numbers for Node and npm match the installer that you downloaded.

You should now be able to open your Linux distribution and run node, npm, and UNIX commands as usual.

Alternative WSL installation method

If the above method didn’t work, one alternative method for installing Node on WSL is to use the Node Version Manager (nvm).

The linked page from Microsoft has information on installing Node for WSL using nvm: https://docs.microsoft.com/en-us/windows/nodejs/setup-on-wsl2

Related topics: