當前位置: 首頁>>技術問答>>正文


無法在ubuntu上安裝npm

, , ,

問題描述

試圖在ubuntu 12.04上安裝nodejs和npm。我用Google搜索並做到了。現在,我無法在機器上安裝npm。

sudo apt-get install npm

這給了我這個

The following packages have unmet dependencies:
 npm : Depends: nodejs but it is not going to be installed
       Depends: nodejs-dev
       Depends: node-request but it is not going to be installed
       Depends: node-mkdirp but it is not going to be installed
       Depends: node-minimatch but it is not going to be installed
       Depends: node-semver but it is not going to be installed
       Depends: node-ini but it is not going to be installed
       Depends: node-graceful-fs but it is not going to be installed
       Depends: node-abbrev but it is not going to be installed
       Depends: node-nopt but it is not going to be installed
       Depends: node-fstream but it is not going to be installed
       Depends: node-rimraf but it is not going to be installed
       Depends: node-tar 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.

最佳解決方法

這看起來你可能安裝了chris-lea node.js ppa,這很好。但是,你沒有從那個ppa安裝npm,因為它破壞了debian包的工作方式。相反,隻需安裝nodejs即可。安裝完成後,運行npm -v,您應該會看到它已安裝完畢。如果您沒有使用chris-lea ppa更新您在Googled的網頁上的問題,以了解如何在Ubuntu上安裝nodejs。

次佳解決方法

嘗試安裝這樣的NodeJ:

sudo apt-get install nodejs

由於NodeJ安裝節點和npm

第三種解決方法

我按照this documentation解決了這個問題。

要記住使用npm的指針:

mkdir ~/nodejs/ && cd ~/nodejs
sudo apt-get install npm
npm install
npm update

在開發應用程序時,如果nodejs需要任何特定模塊,則運行

cd ~/nodejs
npm install modulename   #for example sendgrid

有時,模塊需要全局安裝;然後用

sudo npm install modulename -g"

要刪除模塊:

cd ~/nodejs
npm uninstall modulename          # if locally installed or 
sudo npm uninstall modulename -g  # if globally installed

npm prune有助於刪除未滿足的依賴項

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/6731.html,未經允許,請勿轉載。