簡體   English   中英

在Ubuntu 14.04上安裝Node 5.x和最新的或正在運行的npm

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

我在Azure上有一個Ubuntu 14.04虛擬機。 我只是嘗試升級node和npm,但似乎已損壞它。 我已刪除並清除了緩存,並多次清除了緩存。 將安裝nodejs,但不會安裝npm。

> node -v
v5.1.1

我為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.

我的apt-get更新如下所示:

> 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

你可以試試這個

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

=>關閉並重新打開終端以開始使用NVM

source ~/.profile
nvm ls-remote

如果看到任何錯誤,請安裝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

希望這對您有幫助:)

解決此問題的最簡單方法; 是從nodejs.org下載最新版本的壓縮包,然后將nodenpm二進制文件添加到您的路徑中。

為確保一切順利,首先刪除通過軟件包系統安裝的版本,下載tar,解壓縮,然后將所得路徑添加到$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

現在,只需將bin/目錄添加到$PATH並重新啟動Shell。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM