安装节点/运行npm install的问题

Sar*_*rah 4 ubuntu node.js npm

我对Linux不是很熟练所以请耐心等待...

我正在尝试使用以下说明安装Node.js:

sudo apt-get update
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs=0.10.18-1chl1~precise1
Run Code Online (Sandbox Code Playgroud)

可在此处找到:https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

我运行这些命令,在最后一个命令后,我收到了这个错误:

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 resolve the situation:

The following packages have unmet dependencies:
nodejs : Conflicts: npm
E: Unable to correct problems, you have held broken packages.
Run Code Online (Sandbox Code Playgroud)

我接下来尝试运行命令sudo apt-get install nodejs,这没有给我任何错误.

但是,当我运行"npm install"时,它无法显示:

npm ERR! install Couldn't read dependencies
npm ERR! Error: ENOENT, open '/home/sarah/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 3.8.0-30-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /home/sarah
npm ERR! node -v v0.11.8-pre
npm ERR! npm -v 1.3.11
npm ERR! path /home/sarah/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/sarah/npm-debug.log
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)

谁能帮我弄清楚出了什么问题?提前致谢

Pet*_*ons 11

这个命令:sudo apt-get install nodejs=0.10.18-1chl1~precise1只是一个不明智的文档.在常见用例中指定确切的版本号是错误的.所以你使用just sudo apt-get install nodejs是正确的命令,现在一切都应该很好.

之后看起来你已经成功安装了两个node并且npm(它们聚集在一起).现在您正在尝试运行npm install,这通常在节点模块的目录中运行并查找package.json文件.由于您的主目录不是节点模块而且不包含package.json文件,因此会出错.

节点安装正确,你很高兴.您可以开始使用npm init或者可以从github克隆现有模块,例如,cd到该模块的目录,然后运行npm install,这应该可行.