24

I'm using Bash on Ubuntu on Windows as the command line tool.

I need to install Node and NPM, and on the download page for unix I need to choose between 5 different options: 32bits, 64 bits, ArmV6, ArmV7, Armv8. Arms themselves are either 32 or 64 bit so this left me a confused.

Are Arm versions meant for mobile devices? I couldn't find Bash/Ubuntu in any directory, and not in the 64 bit program directory.

If my Windows is 64 bit, can I assume that Bash/Ubuntu will be 64 bits as well, and that that is the right file to download?

1

8 Answers 8

62

To install node and npm in Ubuntu on WSL you need to install nvm. It doesn't work with apt-install

  1. Install NVM

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

  1. Edit ~/.bashrc or ~/.zshrc depending on the Linux Shell you're using and add the following at the bottom

export NVM_DIR="/home/yourusername/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Now restart bash, and then run

nvm install node

That will install the latest, if you wish to install a specific version

nvm install v6.11.5

You're all set.

Credit : https://winsmarts.com/how-to-install-node-on-linux-on-windows-wsl-65069ea5f83d

6
  • currently on 0.37.2 Mar 20, 2021 at 20:31
  • 3
    This worked for me, but the Step #2 you listed there was already done to my Ubuntu WSL distribution in ~/.bashrc, so I did not need to do it. Likely the automated script was changed since the original post to include that automatically. Thanks for the post!
    – Atmas
    Sep 1, 2021 at 16:30
  • 1
    You should use the new official NVM distribution link to install NVM. The official install script is curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
    – Zack
    Jan 24 at 22:00
  • Thanks, this worked! Any idea as to why i'm getting unmatched " on the line [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" when i start the terminal? Everything still works fine it just looks like an error Jan 26 at 19:18
  • you might need to restart shell after Step1 and Step2 if applicable
    – Jacob Joy
    Feb 8 at 10:10
9

According to the link of this comment without NVM

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

As of december 2021, it results in:

√ tik ~ # npm -v
8.1.4
√ tik ~ # node -v
v17.2.0
8
uname -a

Run the above command in WSl.

If it is 64 bit it will display the following

Linux Karthik-Pc 4.4.0-17134-Microsoft #112-Microsoft Thu Jun 07 22:57:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux

If it is 32 bit then it will display

Linux Karthik-Pc 4.4.0-17134-Microsoft #112-Microsoft Thu Jun 07 22:57:00 PST 2018 i686 i686 i686 GNU/Linux

Btw you can easily download node and npm in wsl from apt.

apt-get install -y nodejs
6
  • 4
    I get installed nodejs, and then i run node --verion with no problem. but I don't get npm command running in WSL Ubuntu Jun 1, 2019 at 19:43
  • 1
    Follow these instructions for installing node js link Jun 3, 2019 at 4:29
  • 2
    @KarthikRaja They don't work. Output of which npm is /mnt/c/Program Files/nodejs/npm Aug 23, 2019 at 11:20
  • @UTF_or_Death were you able to fix this? May 23, 2020 at 18:16
  • I followed the instructions on nodejs.org/en/download/package-manager/… They have changed since then, but probably work May 25, 2020 at 18:31
2

Windows has an official support page on how to do this: https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl

Their instructions are (all in your WSL terminal):

  1. Install curl with sudo apt-get install curl
  2. Install nvm with curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash - Note that this is the official place to get NVM from.
  3. Restart your terminal.
  4. Install a version of node with nvm install <version>. For example, I chose nvm install lts/hydrogen to install the latest version of Node 18. You can use nvm ls to see the available versions.
  5. Optionally, you can mark a version as the default using nvm alias default <version> so that it's automatically set whenever you open a terminal.
2

A great alternative to nvm is Volta

To install volta

curl https://get.volta.sh | bash

Volta is pretty cool alternative to nvm To install a specific version of node

volta install node@<version>
1
  • Perhaps relevant to add why it is superior to nvm - the ability to pin project to node version easily across collaborators?
    – Ben Carp
    Nov 24 at 6:31
1

You need to update the WSL packages and repositories for you to get nodejs. Use the following set of commands to accomplish the same:

sudo apt update
sudo apt upgrade -y
sudo apt install nodejs -y
0

If you're encountering issues even after running sudo apt install npm, it's possible that the npm binary is not in your system's PATH. Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Check if npm is installed: After running the installation command, check if npm is installed by running the following command:

    npm -v

    If npm is installed, you should see its version number. If you still get a "command not found" error, proceed to the next steps.

  2. Verify the npm binary location: Find out where npm is installed by checking the path to its binary. You can use the which command:

    which npm

    This will show the path to the npm binary. If it doesn't return anything, npm may not be installed correctly.

  3. Check the npm installation log: Review the installation log to see if there were any errors during the installation:

    cat /var/log/apt/history.log | grep npm

    Look for any error messages that might indicate what went wrong during the installation.

  4. Reinstall npm: If there are issues, you can try reinstalling npm:

    sudo apt remove npm && sudo apt install npm

    After reinstalling, check again if npm is in your PATH and if the issue persists.

  5. Verify Node.js installation: Sometimes, npm issues can be related to Node.js. Ensure that Node.js is installed:

    node -v

    If Node.js is not installed, you can install it using the following command:

    sudo apt install nodejs

    Then, retry installing npm:

    sudo apt install npm

There you goooo!!!

1
-1

Try to upgrade all your plugins in apk. Run the below command in WSl.

sudo apt-get update && sudo apt-get upgrade
1
  • Yes absolutely! Followed by sudo apt install nodejs Apr 17, 2022 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.