Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm show "NPM ELF : not found error" in WSL

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
like image 331
Anas Avatar asked Dec 21 '25 20:12

Anas


1 Answers

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!

like image 55
Ella Jameson Avatar answered Dec 23 '25 14:12

Ella Jameson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!