0

I am trying to install nodejs and npm packages on Ubuntu 16.04, and getting same errors every time. I have tried commands listed below -

1.

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

(didn't work)

2.

sudo apt-get install nodejs-legacy
sudo apt-get install npm

(didn't work)

3.

curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs

(from this page on nodesource.com)

sudo apt-get install npm

(again it didn't work)

Every time I am getting this error block generated on terminal -

The following packages have unmet dependencies:
npm : Depends: nodejs but it is not going to be installed
Depends: node-abbrev (>= 1.0.4) but it is not going to be installed
Depends: node-ansi (>= 0.3.0-2) but it is not going to be installed
Depends: node-ansi-color-table but it is not going to be installed
Depends: node-archy but it is not going to be installed
Depends: node-block-stream but it is not going to be installed
Depends: node-fstream (>= 0.1.22) but it is not going to be installed
Depends: node-fstream-ignore but it is not going to be installed
Depends: node-github-url-from-git but it is not going to be installed
Depends: node-glob (>= 3.1.21) but it is not going to be installed
Depends: node-graceful-fs (>= 2.0.0) but it is not going to be installed
Depends: node-inherits but it is not going to be installed
Depends: node-ini (>= 1.1.0) but it is not going to be installed
Depends: node-lockfile but it is not going to be installed
Depends: node-lru-cache (>= 2.3.0) but it is not going to be installed
Depends: node-minimatch (>= 0.2.11) but it is not going to be installed
Depends: node-mkdirp (>= 0.3.3) but it is not going to be installed
Depends: node-gyp (>= 0.10.9) but it is not going to be installed
Depends: node-nopt (>= 3.0.1) but it is not going to be installed
Depends: node-npmlog but it is not going to be installed
Depends: node-once but it is not going to be installed
Depends: node-osenv but it is not going to be installed
Depends: node-read but it is not going to be installed
Depends: node-read-package-json (>= 1.1.0) but it is not going to be installed
Depends: node-request (>= 2.25.0) but it is not going to be installed
Depends: node-retry but it is not going to be installed
Depends: node-rimraf (>= 2.2.2) but it is not going to be installed
Depends: node-semver (>= 2.1.0) but it is not going to be installed
Depends: node-sha but it is not going to be installed
Depends: node-slide but it is not going to be installed
Depends: node-tar (>= 0.1.18) but it is not going to be installed
Depends: node-underscore but it is not going to be installed
Depends: node-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

4.

sudo aptitude install npm

(reference: Unable to correct problems, you have held broken packages)

Using this I installed npm, but I got older versions of both npm and nodejs. Those are useless as I further need to install webpack.js I used

sudo npm install webpack

and output I get is -

WARN engine webpack@4.1.1: wanted: {"node":">=6.11.5"} (current: 
{"node":"4.2.6","npm":"3.5.2"})
loadDep:yeoman-generator  \ |############################---------------------------------------------------------------------------------------------------------|
loadDep:yeoman-generator  / |############################---------------------------------------------------------------------------------------------------------|
loadDep:yeoman-generator  / |############################---------------------------------------------------------------------------------------------------------|
loadDep:tapable -> 304    - |##############################-------------------------------------------------------------------------------------------------------|
npm WARN deprecated babel-preset-es2015@6.24.1: 🙌  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! 
npm WARN deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info.
/usr/local/bin/webpack-cli -> /usr/local/lib/node_modules/webpack-cli/bin/webpack.js
/usr/local/lib
+-- UNMET PEER DEPENDENCY webpack@^4.0.0
+       
`--     
## dependencies installed & to be installed listed here (this list is quite long)
+       
npm WARN webpack-cli@2.0.12 requires a peer of webpack@^4.0.0 but none was installed.

So the actual question is, how can I install npm, nodejs and webpack with correct versions? Please tell me if I am missing anything in this process of installation of these packages.

marked as duplicate by karel, Eric Carvalho, waltinator, user68186, David Foerster Mar 22 '18 at 13:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • thanks for helping, but I have tried that and didn't work! – Pooja Mar 20 '18 at 10:22
  • this helped to explore the issue, and I updated the question! – Pooja Mar 20 '18 at 10:36
  • 2
    It seems that you installed an old version of node.js. The nodesource blog post you linked to is 3 years old. There are official and up-to-date installation instructions on nodejs.org. You probably have to uninstall the old version first. – danzel Mar 20 '18 at 11:11
  • 1
    @danzel That's not a comment: That's an answer... If you answer and ping me, I'll come back and upvote... – Fabby Mar 20 '18 at 17:47