I have been using the Windows Subsystem for Linux (WSL2) on my Windows machine to learn web devlopment. While trying to use Mongoose on Node, I was unable to run it as I was running Node v10 and the minimum requirement for running Mongoose was Node v12. I am documenting the commands I used to install Node.js on Windows Subsystem for Linux (WSL2).

Installing nvm, node.js, and npm

  • Start up the Ubuntu terminal on your system. I am using the Windows Terminal.
  • Install cURL (a tool used for downloading content from the internet in the command-line) with: sudo apt-get install curl
  • Install nvm, with: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash (Note: that at the time of writing this article, the latest version of nvm is 0.39.0. Please modify the command and substitute it with the latest version of nvm)
  • Verify the installation with: command -v nvm …this should return nvm. If the outsput you recieve is command not found  or you don’t recieve any response at all, please restart your terminal and try again.
  • Type nvm ls to view a complete list of Node installations on your system.
  • Install the latest versions of the stable and LTS versions of node:
    • nvm install --lts will install the latest LTS version of Node
    • nvm install node will install the latest stable version of Node
  • Now, when you run nvm ls the output will show that both the LTS and stable versions of Node are installed on the system.
  • You can check the which versions of Node and npm are installed with node --version and npm --version.
  • To change the version of Node that is used on a specific project, move in to the project folder and run nvm use node to use the stable version or run nvm use --lts to switch to the LTS version.
  • You can also begin using a specific version of Node by running the command nvm use vx.x.x where x.x.x is a prticular version of Node, for example, running  nvm use v14.3.0 will use Node v14.3.0.

Leave a Reply

Your email address will not be published. Required fields are marked *