【问题标题】:E: Unable to locate package npmE: 找不到包 npm
【发布时间】:2018-05-02 11:38:38
【问题描述】:

当我尝试使用sudo apt-get install npm 安装 npm 时,出现以下错误:

E: 找不到包 npm

为什么apt找不到npm?我正在使用 Debian 9 并且已经运行了

sudo apt-get install nodejs

【问题讨论】:

  • 这可能更适合 superuser.com,因为它不是编程问题。

标签: node.js npm debian apt-get apt


【解决方案1】:

来自官方 Node.js 文档:

Debian Sid(不稳定)、Jessie(测试)和 Wheezy(wheezy-backports)的官方 repo 中也提供了一个 Node.js 包作为“nodejs”。 它只安装一个 nodejs 二进制文件。

因此,如果您只输入 sudo apt-get install nodejs ,它不会安装其他好东西,例如 npm

您需要输入:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

可选:安装构建工具

要从 npm 编译和安装本机插件,您可能还需要安装构建工具:

sudo apt-get install -y build-essential

更多信息:Docs NodeJs

【讨论】:

  • @gokcand 你知道为什么 npm 在 Debian 存储库中不可用吗?
  • 当我运行这个时:curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - 我得到这个输出:+ apt-get install -y lsb-release > /dev/null 2>&1Error executing command, exiting
  • 在尝试了这个和许多其他建议(所有这些都有优点)之后,我沮丧地关闭了终端。我后来回来再试一次,它从一开始就正常工作。似乎每个人都遗漏的部分是在安装后打开和关闭终端,即再次打开和关闭它;)我应该知道尝试一下。
【解决方案2】:

在 Ubuntu for Windows 中遇到这个,先试试运行

sudo apt-get update
sudo apt-get upgrade

然后

sudo apt-get install npm

【讨论】:

【解决方案3】:

我在 Debian 9.2 上遇到了同样的问题,这就是我要解决的问题。

安装

sudo apt install curl
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
sudo apt-get install -y nodejs
sudo apt-get install -y npm

检查已安装的版本

node --version
npm --version

最初来自“如何在 Debian 9 上安装 Node.js LTS” http://linuxbsdos.com/2017/06/26/how-to-install-node-js-lts-on-debian-9-stretch/

【讨论】:

  • 没有官方的Debian安装npm的方式吗? npm 说它与 node.js 捆绑在一起,那为什么我做 apt install nodejs 时它不可用?
  • 为我工作!您可以使用curl -sL https://deb.nodesource.com/setup_lts.x | sudo bash - 获取最新的 lts 版本。
【解决方案4】:

您的系统找不到 npm 包,因为您尚未将 nodejs 存储库添加到您的系统..

尝试按照以下安装步骤操作:
将 nodejs PPA 存储库添加到我们的系统和 python 软件属性中

sudo apt-get install curl python-software-properties 
// sudo apt-get install curl software-properties-common

curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get update

然后安装 npm

sudo apt-get install nodejs

检查 npm 和 node 是否已安装并且您已准备好使用 node.js

node -v
npm -v

如果有人安装 nodejs 失败.. 尝试先删除 npm, 也许旧的安装被破坏了..

sudo apt-get remove nodejs
sudo apt-get remove npm

检查 npm 或 node 文件夹是否仍然存在,如果找到则将其删除

which node
which npm

【讨论】:

  • (我在 Debian Jessie 派生的 Bunsen-Helium 上)sudo apt-get install curl python-software-properties 让我窒息,所以不得不将其更改为:sudo apt-get install curl software-属性-常见
  • (现在最高到 10.x) $ curl -sL deb.nodesource.com/setup_10.x | sudo bash -
  • 感谢您的评论,我已经更新了答案@AAAfarmclub
  • 在 Ubunntu 20.04.1 LTS 中安装 Node 和 NPM 成功
【解决方案5】:

对于 Debian Stretch(Debian 版本 9),nodejs 不包括 npm,并且要将其作为单独的软件包安装,您必须启用 stretch-backports

echo 'deb http://deb.debian.org/debian stretch-backports main' |
sudo tee /etc/apt/sources.list.d/stretch-backports.list
apt-get update -y
apt-get -t stretch-backports install -y npm

在 Buster (Debian 10) 中,npm 是一个常规软件包,因此今后应该可以正常工作。但在未来一段时间内,我们中的一些人仍会部分卡在 Stretch box 上。

【讨论】:

  • 100% 正确。如果您不知道自己是否在使用 Debian Stretch,请运行“lsb_release -a”,如果是,请遵循此答案。
【解决方案6】:

这将解决您的错误。在终端中运行这些命令。这些命令将添加旧版本。您可以稍后更新它们,也可以在逐个运行这些命令之前在此处更改版本。

sudo apt-get install build-essential
wget http://nodejs.org/dist/v0.8.16/node-v0.8.16.tar.gz
tar -xzf node-v0.8.16.tar.gz
cd node-v0.8.16/
./configure
make
sudo make install

【讨论】:

  • 谢谢,这个:'sudo apt-get install build-essential' 为我修复了它
  • 从源代码安装意味着您不会获得任何安全更新,除非您自己获取它们并在有新补丁可用时构建新的本地版本。
【解决方案7】:

在我的 jenkins/jenkins docker sudo 中总是产生错误:

bash: sudo: command not found

我需要更新 repo 列表:

curl -sL https://deb.nodesource.com/setup_10.x | apt-get update

那么,

 apt-get install nodejs

所有命令行结果如下:

root@76e6f92724d1:/# curl -sL https://deb.nodesource.com/setup_10.x | apt-get update
Ign:1 http://deb.debian.org/debian stretch InRelease
Get:2 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Get:3 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:4 http://deb.debian.org/debian stretch Release [118 kB]
Get:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [520 kB]
Get:6 http://deb.debian.org/debian stretch-updates/main amd64 Packages [27.9 kB]
Get:8 http://deb.debian.org/debian stretch Release.gpg [2410 B]
Get:9 http://deb.debian.org/debian stretch/main amd64 Packages [7083 kB]
Get:7 https://packagecloud.io/github/git-lfs/debian stretch InRelease [23.2 kB]
Get:10 https://packagecloud.io/github/git-lfs/debian stretch/main amd64 Packages [4675 B]
Fetched 7965 kB in 20s (393 kB/s)
Reading package lists... Done
root@76e6f92724d1:/#  apt-get install nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libicu57 libuv1
The following NEW packages will be installed:
  libicu57 libuv1 nodejs
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 11.2 MB of archives.
After this operation, 45.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian stretch/main amd64 libicu57 amd64 57.1-6+deb9u3 [7705 kB]
Get:2 http://deb.debian.org/debian stretch/main amd64 libuv1 amd64 1.9.1-3 [84.4 kB]
Get:3 http://deb.debian.org/debian stretch/main amd64 nodejs amd64 4.8.2~dfsg-1 [3440 kB]
Fetched 11.2 MB in 26s (418 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libicu57:amd64.
(Reading database ... 12488 files and directories currently installed.)
Preparing to unpack .../libicu57_57.1-6+deb9u3_amd64.deb ...
Unpacking libicu57:amd64 (57.1-6+deb9u3) ...
Selecting previously unselected package libuv1:amd64.
Preparing to unpack .../libuv1_1.9.1-3_amd64.deb ...
Unpacking libuv1:amd64 (1.9.1-3) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_4.8.2~dfsg-1_amd64.deb ...
Unpacking nodejs (4.8.2~dfsg-1) ...
Setting up libuv1:amd64 (1.9.1-3) ...
Setting up libicu57:amd64 (57.1-6+deb9u3) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Setting up nodejs (4.8.2~dfsg-1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode

【讨论】:

    【解决方案8】:

    使用以下命令下载存储库密钥:

    curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
    

    然后设置存储库:

    sudo sh -c "echo deb https://deb.nodesource.com/node_8.x cosmic main \
                     > /etc/apt/sources.list.d/nodesource.list"
    sudo apt-get update
    sudo apt-get install nodejs
    

    【讨论】:

      【解决方案9】:

      我遇到了类似的问题,这对我有用。

      添加 NodeSource 包签名密钥:

      curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
      # wget can also be used:
      # wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
      

      添加所需的 NodeSource 存储库:

      # Replace with the branch of Node.js or io.js you want to install: node_6.x, node_12.x, etc...
      VERSION=node_12.x
      # The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
      # - For Debian distributions: jessie, sid, etc...
      # - For Ubuntu distributions: xenial, bionic, etc...
      # - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
      DISTRO="$(lsb_release -s -c)"
      echo "deb https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
      echo "deb-src https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
      

      更新包列表并安装Node.js:

      sudo apt-get update
      sudo apt-get install nodejs
      

      【讨论】:

        【解决方案10】:

        如果你已经安装了 nodejs,那么你也有 npm。 npm自带node。

        【讨论】:

        • 我刚刚偶然发现了这个问题stackoverflow.com/q/47364736/3961881。它也可能回答你的问题。
        • 死链接。另外,Jacs 是对的,npm 没有安装在 node 上,至少在 Debian 上没有。
        猜你喜欢
        • 2013-01-20
        • 1970-01-01
        • 2015-05-10
        • 2020-03-30
        • 1970-01-01
        • 2019-09-25
        • 1970-01-01
        • 2022-08-04
        • 2019-02-07
        相关资源
        最近更新 更多