2013-04-30 45 views
188

Tôi đang cố gắng cài đặt Node.js trên ubuntu 12.10 của tôi, nhưng nhà ga chỉ cho tôi một lỗi về gói bị mất, tôi đã cố gắng với điều này:Cài đặt Node.js trên Ubuntu 12.10

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 

Nhưng khi tôi đến dòng cuối cùng sudo apt-get install nodejs npm chỉ cho tôi một lỗi:

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. 

Sau đó, tôi gỡ cài đặt ppa:chris-lea/node.js và tôi đã cố gắng một lựa chọn thứ hai:

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 

Lỗi tương tự, thiết bị đầu cuối nói npm is in last version nhưng cũng hiển thị cho tôi văn bản tôi hiển thị ở trên cùng. Tôi nghĩ rằng vấn đề là ppa:chris-lea/node.js nhưng tôi không biết làm thế nào giải quyết nó.

+0

Bạn đã thử xây dựng NodeJS từ tệp nhị phân chưa? – freakish

+0

Tôi đến đây vì lệnh 'grunt' và' node' của tôi không hiển thị bất kỳ thông tin lỗi, trợ giúp hoặc phiên bản nào. Tôi làm theo các bước trong [câu trả lời này] (http://stackoverflow.com/a/16303380/881224), và chắc chắn để loại bỏ 'node' và' nodejs' trước. Sau đó, tôi đã cài đặt * chỉ * 'nodejs', hoạt động. – Droogans

Trả lời

465

Đơn giản chỉ cần làm theo hướng dẫn cho here:

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.

Đừng đưa sudo apt-get install nodejs npm chỉ sudo apt-get install nodejs

+26

Và nếu bạn nhận được lỗi 'sudo: add-apt-repository: lệnh không tìm thấy' chỉ cần chạy lệnh này * trước * vào câu lệnh thứ hai ở trên:' sudo apt-get install software-properties-common' – rs77

+2

Tôi cũng có lỗi 'sudo: add-apt-repository: lệnh không tìm thấy' và cần thiết để chạy' sudo apt-get install python-software-properties' trước khi thêm kho lưu trữ – acw

+0

thử sử dụng 'bash -r' nếu bạn có phiên bản cũ trước hoặc nút/npm không xuất hiện trong bảng điều khiển của bạn. Nó sẽ cập nhật đường dẫn. – Michael

15

npm được tự động cài đặt với node.js trong phiên bản mới nhất của nút. Bạn thấy gì khi nhập node --versionnpm --version trong thiết bị đầu cuối?

Bạn có thể nâng cấp NPM sử dụng NPM bản thân cũng

[sudo] npm install -g npm 
+0

Điều này làm việc tốt cho tôi! – sleepycal

13

My apt-get đã già và busted, vì vậy tôi đã phải cài đặt từ nguồn. Đây là những gì làm việc cho tôi:

# get the latest version from nodejs.org. At the time of this writing, it was 0.10.24 
curl -o ~/node.tar.gz http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz 
cd 
tar -zxvf node.tar.gz 
cd node-v0.6.18 
./configure && make && sudo make install 

Những bước này được lấy chủ yếu từ joyent's installation wiki

+0

Đối với phiên bản mới nhất, bạn cũng có thể sử dụng URL http://nodejs.org/dist/node-latest. tar.gz – rednaw

4

Bạn có thể sử dụng nvm để cài đặt nodejs. Nó cho phép bạn làm việc với các phiên bản khác nhau mà không có xung đột.

+0

Đây là cách để đi nếu bạn muốn sự linh hoạt của việc có các phiên bản nút khác nhau và có thể cài đặt phiên bản mới nhất và tuyệt vời nhất. – demisx

40

Tính đến hôm nay, bạn chỉ có thể cài đặt nó với:

sudo apt-get install nodejs 
+1

Nếu sử dụng python execjs.get(), điều này sẽ không trả về một động cơ. Tuy nhiên, nếu tôi sử dụng 'apt-get install python-software-properties python g ++ make add-apt-repository ppa: chris-lea/node.js apt-get update' apt-get install nodejs – mtnpaul

+0

Hãy nhớ rằng, đó là cài đặt không bao gồm npm. – GusDeCooL

+0

Cũng có sẵn là 'sudo apt-get install nodejs-legacy' ' sudo apt-get install npm' – Red15

3

Bạn cũng có thể biên dịch nó từ nguồn như thế này

git clone git://github.com/ry/node.git 
cd node 
./configure 
make 
sudo make install 

Tìm hướng dẫn chi tiết ở đây http://howtonode.org/how-to-install-nodejs

3
sudo apt-get install g++ curl libssl-dev apache2-utils 
sudo apt-get install git-core 
git clone git://github.com/ry/node.git 
cd node 
./configure 
make 
sudo make install 

http://jstricks.com/install-node-js/

8

Đây là cách tốt nhất để dễ dàng cài đặt NODE.JS. Đây cũng là thực tế cho Ubuntu 12.04, 13.04 và 14,04

Thêm nút js kho

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

nút.js cài đặt

[sudo] apt-get install nodejs 

Bây giờ kiểm tra Node.js phiên bản

node -v 

Đầu ra

v0.10.20 

Lệnh này nên cài đặt NPM.

npm install 

phiên bản Kiểm tra NPM

npm -v 

Đầu ra

1.4.3 

Nếu vì một số lý do, nếu bạn thấy NPM không được cài đặt, bạn có thể thử chạy:

[sudo] apt-get install npm 

Để cập nhật NPM bạn có thể thử chạy:

[sudo] npm install -g npm 
4
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.19.0/install.sh | bash  

nvm install v0.10.33 

chỉ cần sử dụng nvm cho điều khiển phiên bản nút nvm

1

Cá nhân tôi làm điều đó theo cách này:

sudo apt-get install python g++ make 
wget http://nodejs.org/dist/node-latest.tar.gz 
tar xvfvz node-latest.tar.gz 
cd node-v0.12.0 
./configure 
make 
sudo make install 

Nếu bạn muốn cài đặt phiên bản cụ thể hơn tải xuống phiên bản bạn muốn từ trang web nodejs và thực hiện các bước cây cuối cùng.
Tôi thực sự khuyên bạn không nên sử dụng gói nodejs mặc định từ thị trường phân phối vì nó có lẽ sẽ lỗi thời. (tức là hiện tại cho thời điểm viết điều này trong thị trường ubuntu là v0.10.25 quá cũ so với phiên bản mới nhất (v0.12.0)).

3

Thực hiện theo các hướng dẫn được đưa here tại NodeSource được dành riêng cho việc tạo ra một hệ sinh thái bền vững cho Node.js

Đối với Node.js> = 4.x

# Using Ubuntu 
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - 
sudo apt-get install -y nodejs 

# Using Debian, as root 
curl -sL https://deb.nodesource.com/setup_4.x | bash - 
apt-get install -y nodejs 
3

Bây giờ bạn có thể dễ dàng cài đặt với:

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

Đảm bảo bạn có trăn và c được cài đặt sẵn.Nếu không thực hiện:

sudo apt-get install python g++ make 
1

mô tả ở đây đầy đủ để tạo ra chương trình đầu tiên sử dụng máy phát điện nhanh

Ubuntu's package manager

Để cài đặt Node và NPM qua apt-get, chạy các lệnh sau:

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

Express application generator

$ npm install express-generator -g 

Display the command options with the -h option:

$ 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 

For example, the following creates an Express app named myapp in the current working directory:

$ 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 

Then install dependencies:

$ cd myapp 
$ npm install 

run the app with this command:

$ DEBUG=myapp:* npm start 

Then load http://localhost:3000/ in your browser to access the app.

The generated app has the following directory structure:

├── 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 
1

Cài đặt Node.js trên Ubuntu 12.10 hoặc 14.04 LTS hoặc 16.04.1 LTS

Vui lòng tránh cài đặt Node.js với apt-get trên Ubuntu. Nếu bạn đã cài đặt Node.js bằng trình quản lý gói tích hợp sẵn, vui lòng xóa nó. (sudo apt-get purge nodejs && sudo apt-get autoremove && sudo apt-get autoclean)

Quy trình cài đặt trên Linux giống như trên OSX. Với tập lệnh được cung cấp:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash 

$ nvm list 
$ nvm ls-remote 
$ nvm install 6.4.0 
$ nvm use 6.4.0 
$ nvm alias default 6.4.0 
$ node -v 
$ npm install -g npm 
$ npm -v 

Một điều nữa! Đừng quên chạy lệnh sau, điều này làm tăng số lượng đồng hồ inotify.

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p 

Hy vọng điều này sẽ giúp bạn!

Các vấn đề liên quan