我试图在Ubuntu 12.10 (Quantal Quetzal)上安装Node.js,但终端显示关于丢失包的错误。我试过这样做:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

但是当我来到最后一行sudo apt-get install nodejs npm显示这个错误:

Failed to install some packages. This may mean that
you requested an impossible situation or if you are using the distribution
distribution that some required packages have not yet been created or been
been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nodejs: Conflicts: npm
E: Failed to correct problems, you have held broken packages.

然后我卸载了ppa:chris-lea/node.js,我正在尝试第二种选择:

sudo apt-get install node.js
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

同样的错误,终端说npm是最新版本,但它也显示了我在顶部显示的文本。我认为问题是ppa:chris-lea/node.js,但我不知道如何解决它。


当前回答

下面是使用express生成器创建第一个程序的完整描述,

Ubuntu的包管理器

通过apt-get安装Node.js和npm,运行这些命令:

sudo apt-get update
sudo apt-get install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo apt-get install npm

快速应用程序生成器:

$ npm install express-generator -g

使用-h选项显示命令选项:

$ express -h

  Usage: express [options] [dir]

  Options:

    -h, --help          output usage information
    -V, --version       output the version number
    -e, --ejs           add ejs engine support (defaults to jade)
        --hbs           add handlebars engine support
    -H, --hogan         add hogan.js engine support
    -c, --css <engine>  add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
        --git           add .gitignore
    -f, --force         force on non-empty directory

例如,下面在当前工作目录中创建一个名为myapp的Express应用程序:

$ express myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   create : myapp/public/javascripts
   create : myapp/public/images
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css
   create : myapp/views
   create : myapp/views/index.jade
   create : myapp/views/layout.jade
   create : myapp/views/error.jade
   create : myapp/bin
   create : myapp/bin/www

然后安装依赖项:

$ cd myapp
$ npm install

用下面的命令运行app:

$ DEBUG=myapp:* npm start

然后在浏览器中加载http://localhost:3000/以访问应用程序。

生成的应用程序具有以下目录结构:

├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.jade
    ├── index.jade
    └── layout.jade

7 directories, 9 files

其他回答

现在你可以简单地安装:

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

确保预先安装了Python和C解释器/编译器。如果没有,执行:

sudo apt-get install python g++ make

下面是使用express生成器创建第一个程序的完整描述,

Ubuntu的包管理器

通过apt-get安装Node.js和npm,运行这些命令:

sudo apt-get update
sudo apt-get install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo apt-get install npm

快速应用程序生成器:

$ npm install express-generator -g

使用-h选项显示命令选项:

$ express -h

  Usage: express [options] [dir]

  Options:

    -h, --help          output usage information
    -V, --version       output the version number
    -e, --ejs           add ejs engine support (defaults to jade)
        --hbs           add handlebars engine support
    -H, --hogan         add hogan.js engine support
    -c, --css <engine>  add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
        --git           add .gitignore
    -f, --force         force on non-empty directory

例如,下面在当前工作目录中创建一个名为myapp的Express应用程序:

$ express myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   create : myapp/public/javascripts
   create : myapp/public/images
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css
   create : myapp/views
   create : myapp/views/index.jade
   create : myapp/views/layout.jade
   create : myapp/views/error.jade
   create : myapp/bin
   create : myapp/bin/www

然后安装依赖项:

$ cd myapp
$ npm install

用下面的命令运行app:

$ DEBUG=myapp:* npm start

然后在浏览器中加载http://localhost:3000/以访问应用程序。

生成的应用程序具有以下目录结构:

├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.jade
    ├── index.jade
    └── layout.jade

7 directories, 9 files

这是轻松安装Node.js的最佳方式。这也适用于Ubuntu 12.04 (Precise穿山甲),Ubuntu 13.04 (Raring Ringtail)和Ubuntu 14.04 (Trusty Tahr)。

添加Node.js存储库

[sudo] apt-get install python-software-properties
[sudo] apt-add-repository ppa:chris-lea/node.js
[sudo] apt-get update

node . js安装

[sudo] apt-get install nodejs

现在检查Node.js版本

node -v

输出

v0.10.20

这个命令应该安装npm

npm install

检查npm版本

npm -v

输出

1.4.3

如果出于某种原因,如果你看到npm没有安装,你可以尝试运行:

[sudo] apt-get install npm

要更新npm,您可以尝试运行:

[sudo] npm install -g npm

Sudo apt安装nodejs 必须安装NPM curl - sl https://deb.nodesource.com/setup_14.x | sudo - e bash - . Sudo apt-get install -y nodejs

简单地按照这里给出的说明:

Example install: sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs It installs current stable Node on the current stable Ubuntu. Quantal (12.10) users may need to install the software-properties-common package for the add-apt-repository command to work: sudo apt-get install software-properties-common As of Node.js v0.10.0, the nodejs package from Chris Lea's repo includes both npm and nodejs-dev.

不要给sudo apt-get install nodejs npm。只需sudo apt-get install nodejs。