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?

urig
  • 16,016
  • 26
  • 115
  • 184
Ben Carp
  • 24,214
  • 9
  • 60
  • 72
  • 1
    I got the best olution in this article: https://winsmarts.com/how-to-install-node-on-linux-on-windows-wsl-65069ea5f83d – Juan Salvador Jun 01 '19 at 20:15

6 Answers6

58

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

Ashish Verma
  • 762
  • 8
  • 14
  • currently on 0.37.2 – AncientSwordRage Mar 20 '21 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 01 '21 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 '23 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 – Radoslav Trenev Jan 26 '23 at 19:18
  • you might need to restart shell after Step1 and Step2 if applicable – Jacob Joy Feb 08 '23 at 10:10
  • I already had a .bash_profile which is why the .bashrc wasn't working. had to add the export script into .bash_profile. In case if anyone has the same problem – AK M Mar 25 '23 at 10:37
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
Timo
  • 2,922
  • 3
  • 29
  • 28
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
Karthik Raja
  • 131
  • 2
  • 9
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.
Zack
  • 941
  • 9
  • 14
0

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
DharmanBot
  • 1,066
  • 2
  • 6
  • 10
Yogesh Aggarwal
  • 1,071
  • 2
  • 12
  • 30
-1

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

sudo apt-get update && sudo apt-get upgrade
Larry
  • 25
  • 6