Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install npm after purge

As I need an updated version of NodeJS, I first remove old version... By:

 apt-get remove --purge nodejs
 apt-get remove --purge node
 apt-get autoremove

... after sucess on install last version of NodeJS, I ran the npm install procedure,

 node --version  # now is ok!
 sudo apt-get install npm  # ERROR!!!!

So, how to install npm in this context (after this purge process)

EDIT:

PS: as I show by link above and inline-comment above, nodejs --version is OK, is good, no problem. This question was about npm and apt-get... And now I see that part of the answer is here.


The error messages, same as this similar question

The following packages have unmet dependencies:
 npm : Depends: nodejs but it is not going to be installed
       Depends: node-abbrev (>= 1.0.4) 
       Depends: nodejs-dev
       ...
       Depends: ... but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
like image 727
Peter Krauss Avatar asked Dec 12 '15 19:12

Peter Krauss


People also ask

How do I reinstall node JS and npm?

b) Reinstalling using a Node installer Using the official Node installer is the easiest way to reinstall Node. js and npm on your Windows environment. To use this option, you can go to the Node. js download page and reinstall the latest Node.

How do I clear and reinstall npm cache?

Run: “npm cache clean –force” npm cache clean --force or npm cache clean -f . This will force delete the npm cache on your computer.


2 Answers

... Nobody say, but the problem is not with my NodeJS or my UBUNTU, the problem is like a bug with sudo apt-get install npm, this command is with a bug: need to fix the message.

As sayd here in similar question, the npm was installed by the modern NodeJS's installation (!!), so apt-get must say "ok, no problem, you have a good and updated npm".

Conclusion:

  1. use only "curl + apt" commands with the correct setup_N.x choice, as illustred in all links posted here. The installation of nodejs will install also npm.

  2. not use apt-get install npm, avoid it. Is a bug.


NOTE: a typical "curl + apt" is

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

and, after sucess with this install procedure, to check npm existence, use

  npm --version

so, if shows a version number (like 3.3.12), npm was installed!

IMPORTANT: to update npm (ex. from 3.3.12 to 3.5.2) not use apt-get (!), use the npm itself,

 sudo npm install npm -g


EDIT 2017

Today, 2017, at UBUNTU 16 LTS, is possible... And using only atp (is most friendly tham apt-get):

sudo apt update
sudo apt install nodejs  # need it first!
sudo apt install npm

... But ...it is the "most updated version of the sluggish LTS", ... check each version (!)...

Step-by-step for a specific version choice (v6.x as illustration), as this tutorial:

  1. curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh

  2. sudo bash nodesource_setup.sh

  3. atp install nodejs

like image 113
5 revs Avatar answered Oct 13 '22 19:10

5 revs


Remove nodejs and fix broken packages.

sudo apt-get --purge remove nodejs node npm
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get -f install
sudo apt-get autoremove

Install nodejs using a PPA

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

Create a symbolic link for node, as many Node.js tools use this name to execute.

sudo ln -s /usr/bin/nodejs /usr/bin/node

To compile and install native addons from npm you may also need to install build tools:

sudo apt-get install -y build-essential
like image 24
Darshan Patel Avatar answered Oct 13 '22 21:10

Darshan Patel