Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sudo apt-get install npm not getting installed

I tried running sudo apt-get install npm it returns me this dialogue below. How can I resolve the issue?

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
npm : Depends: node-gyp (>= 0.10.9) but it is not going to be 
installed
E: Unable to correct problems, you have held broken packages.
like image 647
Tom Avatar asked Oct 13 '25 10:10

Tom


2 Answers

npm gets installed along with nodejs. If you have node installed, you have npm as well.

run node -v to check if node is installed, then run npm -v to do the same for npm.

If nodejs is not installed, check installation instructions here: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

6.x is the current stable branch.

In general, to run a wipe existing node/npm installation and install from scratch, run:

sudo apt remove --purge nodejs node npm
sudo apt clean
sudo apt autoclean
sudo apt install -f
sudo apt autoremove
like image 159
Mitsakos Avatar answered Oct 15 '25 00:10

Mitsakos


The best and easiest way to install node and npm is by nvm(node version manager).

  1. Run the below code to install nvm

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

2.Then run

nvm install node

npm will be installed alongside node

This method will be the easiest and safest way for npm and node installation.

For installing a specific node and npm you can do it like below:

nvm install v6.11.3

Hope this helps.

like image 41
Jithin Avatar answered Oct 15 '25 01:10

Jithin