【问题标题】:npm show "NPM ELF : not found error" in WSLnpm 在 WSL 中显示“NPM ELF:未找到错误”
【发布时间】:2023-01-08 01:19:54
【问题描述】:

运行 npm 时出现错误,我已经尝试重新安装

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

这个问题仍然存在

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

我正在使用 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 命令

npm -v
-bash: /usr/bin/node: cannot execute binary file: Exec format error

【问题讨论】:

    标签: node.js npm windows-subsystem-for-linux


    【解决方案1】:

    我在github中发现了同样的问题

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

    然后我解决这个问题

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

    希望帮助其他人解决同样的问题

    【讨论】:

      【解决方案2】:

      我无法获得此处给出的解决方案。

      the same source 提出的不同解决方案本身链接到 here 对我有用:

      我先删除节点npm完全(准确地说是所有带有名称的包,但我不确定这是必要的)。然后我使用了安装命令:

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

      这适用于 Ubuntu 和节点版本 18,但您也可以找到其他操作系统和版本 (look here)。

      我希望这可以帮助别人。

      【讨论】:

        【解决方案3】:

        似乎是 WSL Ubuntu 22 Jammy 和 8.5.1 包的问题。 您可能很幸运安装了不同的软件包版本,但我对此有疑问。 安装了带有 6.14.4 的 WSL Ubuntu 20,问题消失了。

        【讨论】:

          猜你喜欢
          • 2019-10-21
          • 2018-12-18
          • 2015-10-28
          • 2021-09-06
          • 1970-01-01
          • 1970-01-01
          • 2021-04-19
          • 2022-07-22
          • 2014-09-03
          相关资源
          最近更新 更多