12

i got error when running npm, i've allready try to reinstall with

sudo apt-get remove nodejs npm -y && sudo apt-get install nodejs npm -y

this problem still exist

/usr/bin/node: 1: ELF: not found
/usr/bin/node: 2: : not found
/usr/bin/node: 4: Syntax error: Unterminated quoted string

im using Ubuntu WSL

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

Linux localhost 4.4.0-19041-Microsoft #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 x86_64 x86_64 GNU/Linux

npm -v command

npm -v
-bash: /usr/bin/node: cannot execute binary file: Exec format error
Anas Fanani
  • 685
  • 7
  • 19

3 Answers3

22

This was an issue for me on Windows 10, using WSL2 and Ubuntu 22.04 LTS. The other solutions in this post did not help, and I was unwilling to downgrade to Ubuntu 20. Instead, I managed to fix it by removing all node-related packages with apt and then installing node via nvm as per this guide by Microsoft.

So to remove the packages:

sudo apt-get remove --purge nodejs npm

Then install nvm...

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

Restart the terminal. Then, make sure nvm is installed:

nvm --version

Finally, use nvm to install the latest version of node and npm:

nvm install node

Check to make sure node and npm are installed:

node --version
npm --version

Hope this helps!

Ella Jameson
  • 408
  • 3
  • 8
1

I could not get the solution to work, which was given here.

A different solution propossed from the same source which itself linked to here worked for me:

I first removed node and npm completly (To be precise all packages with the name in it, but I am not sure this is necessary). Then I used the give install command:

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

This is for Ubuntu and node version 18, but you can find other operating systems and versions as well (look here).

I hope this helps someone.

melon_lord
  • 63
  • 8
0

Seems like an issue with WSL Ubuntu 22 Jammy and 8.5.1 package. You may have luck installing a different package version, but I had issues with this. Installed WSL Ubuntu 20 with 6.14.4, issue was gone.