简体   繁体   中英

Install Node 5.x and latest or working npm on Ubuntu 14.04

I have an Ubuntu 14.04 vm on Azure. I just tried to upgrade node and npm and I seem to have broken it. I have removed and purged, and cleared cache several times. nodejs will install, but npm does not install.

> node -v
v5.1.1

I get the following for npm:

> sudo apt-get install npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
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: 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 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 (>= 2.1.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-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

My apt-get update looks like this:

> sudo apt-get update
Ign http://debian.neo4j.org stable/ InRelease
Ign http://azure.archive.ubuntu.com trusty InRelease
Ign http://repo.mongodb.org trusty/mongodb-org/3.0 InRelease
Hit http://security.ubuntu.com trusty-security InRelease
Get:1 http://debian.neo4j.org stable/ Release.gpg [819 B]
Hit http://azure.archive.ubuntu.com trusty-updates InRelease
Hit http://azure.archive.ubuntu.com trusty Release.gpg
Hit http://repo.mongodb.org trusty/mongodb-org/3.0 Release.gpg
Hit http://debian.neo4j.org stable/ Release
Hit http://repo.mongodb.org trusty/mongodb-org/3.0 Release
Hit http://azure.archive.ubuntu.com trusty Release
Hit http://security.ubuntu.com trusty-security/main Sources
Hit http://azure.archive.ubuntu.com trusty-updates/main Sources
Hit http://repo.mongodb.org trusty/mongodb-org/3.0/multiverse amd64 Packages
Hit http://debian.neo4j.org stable/ Packages
Hit http://security.ubuntu.com trusty-security/universe Sources
Hit http://azure.archive.ubuntu.com trusty-updates/universe Sources
Hit http://azure.archive.ubuntu.com trusty-updates/main amd64 Packages
Hit http://security.ubuntu.com trusty-security/main amd64 Packages
Hit http://azure.archive.ubuntu.com trusty-updates/universe amd64 Packages
Hit http://security.ubuntu.com trusty-security/universe amd64 Packages
Hit http://azure.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://azure.archive.ubuntu.com trusty-updates/universe Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Hit http://azure.archive.ubuntu.com trusty/main Sources
Hit http://azure.archive.ubuntu.com trusty/universe Sources
Hit http://azure.archive.ubuntu.com trusty/main amd64 Packages
Hit http://azure.archive.ubuntu.com trusty/universe amd64 Packages
Ign http://debian.neo4j.org stable/ Translation-en_US
Ign http://debian.neo4j.org stable/ Translation-en
Hit http://azure.archive.ubuntu.com trusty/main Translation-en
Hit http://azure.archive.ubuntu.com trusty/universe Translation-en
Ign http://azure.archive.ubuntu.com trusty/main Translation-en_US
Ign http://repo.mongodb.org trusty/mongodb-org/3.0/multiverse Translation-en_US
Ign http://azure.archive.ubuntu.com trusty/universe Translation-en_US
Ign http://repo.mongodb.org trusty/mongodb-org/3.0/multiverse Translation-en
Hit https://deb.nodesource.com trusty InRelease
Hit https://deb.nodesource.com trusty/main Sources
Hit https://deb.nodesource.com trusty/main amd64 Packages
Get:2 https://deb.nodesource.com trusty/main Translation-en_US
Ign https://deb.nodesource.com trusty/main Translation-en_US
Ign https://deb.nodesource.com trusty/main Translation-en
Fetched 819 B in 6s (131 B/s)
Reading package lists... Done

you can try this

sudo apt-get purge node
sudo apt-get purge npm
sudo apt-get autoremove node
sudo apt-get autoremove npm
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash

=> Close and reopen your terminal to start using NVM

source ~/.profile
nvm ls-remote

if you see any error then install git(sudo apt-get install git)

nvm install 5.0 //or any of the version you want to use
nvm use 5.0 ///use the version which ever you want and need not install npm  as it will installed with it

hope this would help you :)

The easiest way to solve this problem; is to download the tarball of the latest release from nodejs.org, and add the node and npm binaries to your path.

To ensure everything is cleared out, start by removing the versions installed via the package system, download the tar, extract it, and then add the resulting path to your $PATH .

  1. sudo apt-get remove --purge node
  2. sudo apt-get remove --purge npm
  3. cd ~ && wget "https://nodejs.org/dist/v5.1.1/node-v5.1.1-linux-x64.tar.gz"
  4. tar xvzf node-v5.1.1-linux-x64.tar.gz && cd node-v5.1.1-linux-x64
  5. PATH=$PATH:~/node-v5.1.1-linux-x64/bin

Now, just add the bin/ directory to your $PATH and restart your shell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM