E: Unable to locate package npm

左心房为你撑大大i 提交于 2019-11-27 20:06:53

问题


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

E: Unable to locate package npm

Why can't apt find npm? Im using Debian 9 and already sudo apt-get install nodejs.


回答1:


From the official Node.js documentation:

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.

So, if you only type sudo apt-get install nodejs , it does not install other goodies such as 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:

sudo apt-get install -y build-essential

More info: Docs




回答2:


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

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/




回答3:


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

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

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

sudo apt-get install nodejs

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

node -v
npm -v

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

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

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

which node
which npm



回答4:


Encountered this in Ubuntu for Windows, try running first

sudo apt-get update

then

sudo apt-get install npm



回答5:


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



回答6:


For Debian Stretch, nodejs does not include npm, and to install it as a separate package, you have to enable 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, npm is 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.




回答7:


Download the the repository key with:

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

Then setup the repository:

$ 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




回答8:


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



来源:https://stackoverflow.com/questions/47371904/e-unable-to-locate-package-npm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!