skip to Main Content

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

4

Answers


  1. Chosen as BEST ANSWER

    i found same problem in github

    https://github.com/microsoft/WSL/issues/8151

    then i fix this problem with

    wget https://gist.githubusercontent.com/lexavey/155a95d803224d7c0af7e225d0d82396/raw/3b4c103e4c3ff702674f96dd12cc412e9c8766ad/fixexec.py
    sudo python3 ./fixexec.py $(realpath $(command -v node))
    node -v
    

    hope help other with same problem


  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. 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!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search