node.js E: 无法定位包 npm

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47371904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:35:22  来源:igfitidea点击:

E: Unable to locate package npm

node.jsnpmdebianapt-getapt

提问by Jacs

When I try to install npm with sudo apt-get install npm, I got following error:

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

E: Unable to locate package npm

E: 无法定位包 npm

Why can't apt find npm? I'm using Debian 9 and already did run

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

sudo apt-get install nodejs

回答by gokcand

From the official Node.js documentation:

来自官方 Node.js 文档:

A Node.js package is also available in the official repo for Debian Sid (unstable), Jessie (testing) and Wheezy (wheezy-backports) as "nodejs". It only installs a nodejs binary.

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

So, if you only type sudo apt-get install nodejs, it does not install other goodies such as npm.

所以,如果你只输入sudo apt-get install nodejs,它不会安装其他好东西,比如npm

You need to type:

你需要输入:

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

Optional: install build tools

To compile and install native add-ons from npm you may also need to install build tools:

可选:安装构建工具

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

sudo apt-get install -y build-essential

More info: Docs

更多信息:文档

回答by trentinb

I ran into the same issue on Debian 9.2, this is what I did to overcome it.

我在 Debian 9.2 上遇到了同样的问题,这就是我为克服它所做的。

Installation

安装

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

Check installed versions

检查已安装的版本

node --version
npm --version

Originally sourced from "How to install Node.js LTS on Debian 9 stretch" http://linuxbsdos.com/2017/06/26/how-to-install-node-js-lts-on-debian-9-stretch/

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

回答by Red

Encountered this in Ubuntu for Windows, try running first

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

sudo apt-get update

then

然后

sudo apt-get install npm

回答by StefansArya

Your system can't find npm package because you haven't add nodejs repository to your system..

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

Try follow this installation step:
Add nodejs PPA repository to our system and python software properties too

尝试按照此安装步骤操作:
将 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

Then install npm

然后安装npm

sudo apt-get install nodejs

Check if npm and node was installed and you're ready to use node.js

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

node -v
npm -v

If someone was failed to install nodejs.. Try remove the npm first, maybe the old installation was broken..

如果有人安装 nodejs 失败.. 尝试先删除 npm,可能旧的安装坏了..

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

Check if npm or node folder still exist, delete it if you found them

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

which node
which npm

回答by Priyank lohan

This will resolve your error. Run these commands in your terminal. These commands will add the older versions. You can update them later or you can change version here too before running these commands one by one.

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

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

回答by tripleee

For Debian Stretch, nodejsdoes not include npm, and to install it as a separate package, you have to enable stretch-backports.

对于 Debian Stretch,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

In Buster, npmis a regular package, so going forward, this should just work. But some of us will still be stuck partially on Stretch boxes for some time to come.

在 Buster 中,它npm是一个常规包,所以继续前进,这应该可以正常工作。但是我们中的一些人在未来一段时间内仍会部分地被困在 Stretch box 上。

回答by uzay95

in my jenkins/jenkins docker sudo always generates error:

在我的詹金斯/詹金斯 docker sudo 总是产生错误:

bash: sudo: command not found

I needed update repo list with:

我需要更新回购列表:

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

then,

然后,

 apt-get install nodejs

All the command line results like this:

所有命令行结果如下:

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

回答by princetology

I had a similar issue and this is what worked for me.

我有一个类似的问题,这对我有用。

Add the NodeSource package signing key

添加 NodeSource 包签名密钥

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

curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key| sudo apt-key 添加 -

wget can also be used:

也可以使用 wget:

wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key| sudo apt-key add -

wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key| sudo apt-key 添加 -

Add the desired NodeSource repository

添加所需的 NodeSource 存储库

Replace with the branch of Node.js or io.js you want to install: node_6.x, node_12.x, etc...

替换成你要安装的Node.js或者io.js的分支:node_6.x、node_12.x等...

VERSION=node_12.x

版本=node_12.x

The below command will set this correctly, but if lsb_release isn't available, you can set it manually:

下面的命令将正确设置它,但如果 lsb_release 不可用,您可以手动设置它:

- For Debian distributions: jessie, sid, etc...

- 对于 Debian 发行版:jessie、sid 等...

- For Ubuntu distributions: xenial, bionic, etc...

- 对于 Ubuntu 发行版:xenial、bionic 等...

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

- 对于 Debian 或 Ubuntu 衍生发行版,您最好的选择是使用与您的发行版所基于的上游发行版相对应的代号。这是一种高级方案,如果您的发行版未在本 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

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" | 须藤 tee -a /etc/apt/sources.list.d/nodesource.list

Update package lists and install Node.js

更新包列表并安装 Node.js

sudo apt-get update sudo apt-get install nodejs

须藤 apt-get 更新须藤 apt-get 安装 nodejs

回答by F.furq

Download the the repository key with:

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

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

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

Then setup the repository:

然后设置存储库:

$ sudo sh -c "echo deb https://deb.nodesource.com/node_8.xcosmic main \

$ sudo sh -c "echo deb https://deb.nodesource.com/node_8.xcosmic main \

/etc/apt/sources.list.d/nodesource.list" $ sudo apt-get update $ sudo apt-get install nodejs

/etc/apt/sources.list.d/nodesource.list" $ sudo apt-get update $ sudo apt-get install nodejs

回答by diogo

If you have installed nodejs, then you also have npm. Npm comes with node.

如果你已经安装了 nodejs,那么你也有 npm。Npm 带有节点。