Ubuntu build NODEJS development environment process sharing _node.js

Source: Internet
Author: User
Tags crc32 curl mkdir unsupported git clone joyent

System environment:

Ubuntu 12.04 LTS 64bit

First, through the Apt-get installation nodejs– failure (can see the following source installation method):

Copy Code code as follows:

~ sudo apt-get Install Nodejs
~ sudo apt-get Install NPM

~ NODE-V
v0.6.12

~ NPM-V
1.1.4


Create working directory
Copy Code code as follows:

~ mkdir Workspace
~ mkdir Workspace/nodejs
~ CD Workspace/nodejs
~ PWD
/home/conan/workspace/nodejs

Installation failed
Copy Code code as follows:

sudo npm install express-g
NPM HTTP GET https://registry.npmjs.org/express
NPM http 304 https://registry.npmjs.org/express
NPM HTTP GET https://registry.npmjs.org/connect/2.7.11
NPM HTTP GET https://registry.npmjs.org/commander/0.6.1
NPM HTTP GET https://registry.npmjs.org/range-parser/0.0.4
NPM HTTP GET https://registry.npmjs.org/mkdirp/0.3.4
NPM HTTP GET https://registry.npmjs.org/cookie/0.1.0
NPM HTTP GET https://registry.npmjs.org/buffer-crc32/0.2.1
NPM HTTP GET https://registry.npmjs.org/fresh/0.1.0
NPM HTTP GET https://registry.npmjs.org/methods/0.0.1
NPM HTTP GET https://registry.npmjs.org/send/0.1.0
NPM HTTP GET https://registry.npmjs.org/cookie-signature/1.0.1
NPM HTTP GET Https://registry.npmjs.org/debug
NPM http 304 https://registry.npmjs.org/commander/0.6.1
NPM http 304 https://registry.npmjs.org/connect/2.7.11
NPM http 304 https://registry.npmjs.org/range-parser/0.0.4
NPM http 304 https://registry.npmjs.org/mkdirp/0.3.4
NPM http 304 https://registry.npmjs.org/cookie/0.1.0
NPM http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
NPM http 304 https://registry.npmjs.org/fresh/0.1.0
NPM http 304 https://registry.npmjs.org/methods/0.0.1
NPM http 304 https://registry.npmjs.org/send/0.1.0
NPM http 304 https://registry.npmjs.org/cookie-signature/1.0.1
NPM http 304 Https://registry.npmjs.org/debug
NPM err! Error installing express@3.2.6
NPM err! Error rolling back express@3.2.6 Error:unknown, UNKNOWN error '/usr/local/lib/node_modules/express '

NPM err! Unsupported
NPM err! Not compatible with your version of node/npm:connect@2.7.11
NPM err! Required: {"node": ">= 0.8.0"}
NPM err! Actual: {"NPM": "1.1.4", "Node": "0.6.12"}
NPM err!
NPM err! System Linux 3.5.0-23-generic
NPM err! Command "Node" "/USR/BIN/NPM" "Install" "Express" "G"
NPM err! Cwd/home/conan/workspace/nodejs
NPM err! Node-v v0.6.12
NPM err! Npm-v 1.1.4
NPM err! Code Enotsup
NPM err! Message Unsupported
NPM err! errno {}
NPM HTTP GET https://registry.npmjs.org/mime/1.2.6
NPM err!
NPM err! Additional logging details can be found in:
NPM err! /home/conan/workspace/nodejs/npm-debug.log
NPM Not OK


System prompts that node and NPM versions are incompatible. may be finally apt-get Source no update caused the problem.

Ii. Download source code installation from GitHub-success

To find the compatible version below, install it manually.
First uninstall the node and NPM just installed

Copy Code code as follows:

~ sudo apt-get autoremove npm
~ sudo apt-get autoremove nodejs
Find Nodejs's official release download: Https://github.com/joyent/node


In Ubuntu, install git first

Copy Code code as follows:
~ sudo apt-get install git

Then, download the Nodejs source code from GitHub
Copy Code code as follows:
~ Git clone git://github.com/joyent/node.git
Cloning into ' node ' ...
Remote:counting objects:100200, done.
Remote:compressing objects:100% (28074/28074), done.
Remote:total 100200 (Delta 78807), reused 90936 (Delta 70473)
Receiving objects:100% (100200/100200), 61.81 MiB | 698 kib/s, done.
Resolving deltas:100% (78807/78807), done.

Enter node directory
Copy Code code as follows:
~ CD Node
~ PWD
/home/conan/workspace/nodejs/node

Switch to the latest release version V0.11.2-release
Copy Code code as follows:
~ Git checkout V0.11.2-release
Branch V0.11.2-release set up to track remote Branch V0.11.2-release from Origin.
Switched to a new branch ' V0.11.2-release '

To install
Copy Code code as follows:
./configure
Make
sudo make install

Installation complete, view node version
Copy Code code as follows:
~ NODE-V
-bash:/usr/bin/node:no such file or directory

Hint error, no node found, check node installation location
Copy Code code as follows:
~ Whereis Node
Node:/usr/local/bin/node

Add Soft Links: node and npm to/usr/bin
Copy Code code as follows:
~ sudo ln-s/usr/local/bin/node/usr/bin/node
~ sudo ln-s/usr/local/bin/npm/usr/bin/npm

We'll look at the node and NPM versions again.
Copy Code code as follows:
~ NODE-V
v0.11.2
~ NPM-V
1.2.21

Install Express below

Copy Code code as follows:
~ sudo npm Install express-g
Express@3.2.6/usr/local/lib/node_modules/express
├──methods@0.0.1
├──fresh@0.1.0
├──range-parser@0.0.4
├──cookie-signature@1.0.1
├──buffer-crc32@0.2.1
├──cookie@0.1.0
├──debug@0.7.2
├──commander@0.6.1
├──mkdirp@0.3.4
├──send@0.1.0 (mime@1.2.6)
└──connect@2.7.11 (pause@0.0.1, qs@0.6.5, bytes@0.2.0, cookie@0.0.5, formidable@1.0.14, send@0.1.1)

The installation was successful.

Third, the establishment of Express project, start the first project

Copy Code code as follows:

~ Express-e Nodejs-demo
Create:nodejs-demo
Create:nodejs-demo/package.json
Create:nodejs-demo/app.js
Create:nodejs-demo/public
Create:nodejs-demo/public/javascripts
Create:nodejs-demo/public/images
Create:nodejs-demo/public/stylesheets
Create:nodejs-demo/public/stylesheets/style.css
Create:nodejs-demo/routes
Create:nodejs-demo/routes/index.js
Create:nodejs-demo/routes/user.js
Create:nodejs-demo/views
Create:nodejs-demo/views/index.ejs
Install dependencies:
$ cd Nodejs-demo && NPM Install
Run the app:
$ node App

Install Dependency Pack

Copy Code code as follows:
~ CD Nodejs-demo
~ sudo npm Install
express@3.2.6 node_modules/express
├──methods@0.0.1
├──fresh@0.1.0
├──range-parser@0.0.4
├──cookie-signature@1.0.1
├──buffer-crc32@0.2.1
├──cookie@0.1.0
├──debug@0.7.2
├──commander@0.6.1
├──mkdirp@0.3.4
├──send@0.1.0 (mime@1.2.6)
└──connect@2.7.11 (pause@0.0.1, qs@0.6.5, bytes@0.2.0, cookie@0.0.5, formidable@1.0.14, send@0.1.1)

Start Program

Copy Code code as follows:
~ Node App.js
Express Server listening on port 3000

Test whether to start successfully curl

Copy Code code as follows:

~ sudo apt-get Install curl
~ Curl localhost:3000

<! DOCTYPE html>
<title>Express</title>
<link rel= ' stylesheet ' href= '/stylesheets/style.css '/>
<body>
<p>welcome to Express</p>
</body>

Nodejs Server log:

Copy Code code as follows:
get/200 6ms-206b

Well, we've successfully prepared the NODEJS development environment in Ubuntu. Now you can enjoy the fun of development.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.