System environment:
Ubuntu 12.04 LTS 64bit
1. Install nodejs through apt-get - failed (you can see the source code installation method below):
~ sudo apt-get install nodejs
~ sudo apt-get install npm
~ node -v
v0.6.12
~ npm -v
1.1.4
Create a working directory
~ mkdir workspace
~ mkdir workspace/nodejs
~ cd workspace/nodejs
~ pwd
/home/conan/workspace/nodejs
Installation failed
sudo npm install express -g
npm http GET /express
npm http 304 /express
npm http GET /connect/2.7.11
npm http GET /commander/0.6.1
npm http GET /range-parser/0.0.4
npm http GET /mkdirp/0.3.4
npm http GET /cookie/0.1.0
npm http GET /buffer-crc32/0.2.1
npm http GET /fresh/0.1.0
npm http GET /methods/0.0.1
npm http GET /send/0.1.0
npm http GET /cookie-signature/1.0.1
npm http GET /debug
npm http 304 /commander/0.6.1
npm http 304 /connect/2.7.11
npm http 304 /range-parser/0.0.4
npm http 304 /mkdirp/0.3.4
npm http 304 /cookie/0.1.0
npm http 304 /buffer-crc32/0.2.1
npm http 304 /fresh/0.1.0
npm http 304 /methods/0.0.1
npm http 304 /send/0.1.0
npm http 304 /cookie-signature/1.0.1
npm http 304 /debug
npm ERR! error installing [email protected]
npm ERR! error rolling back [email protected] Error: UNKNOWN, unknown error '/usr/local/lib/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: [email protected]
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 /mime/1.2.6
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/conan/workspace/nodejs/
npm not ok
System prompts that node and npm versions are incompatible. Maybe it's a problem that the apt-get source has not been updated.
2. Download the source code from github and install it successfully
Below you need to find a compatible version and install it manually.
Uninstall the newly installed node and npm first
~ sudo apt-get autoremove npm
~ sudo apt-get autoremove nodejs
Find the official release download of nodejs: /joyent/node
In ubuntu, install git first
Then, download the nodejs source code from github
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 the node directory
~ pwd
/home/conan/workspace/nodejs/node
Switch the latest release version 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'
Carry out installation
make
sudo make install
Installation is complete, view node version
-bash: /usr/bin/node: No such file or directory
The prompt is error, the node is not found, check the node installation location
node: /usr/local/bin/node
Add soft links: node and npm to /usr/bin
~ sudo ln -s /usr/local/bin/npm /usr/bin/npm
Let's check the node and npm versions again
v0.11.2
~ npm -v
1.2.21
Install express below
[email protected] /usr/local/lib/node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
Installation was successful.
3. Establish an express project and start the first project
~ express -e nodejs-demo
create : nodejs-demo
create : nodejs-demo/
create : nodejs-demo/
create : nodejs-demo/public
create : nodejs-demo/public/javascripts
create : nodejs-demo/public/images
create : nodejs-demo/public/stylesheets
create : nodejs-demo/public/stylesheets/
create : nodejs-demo/routes
create : nodejs-demo/routes/
create : nodejs-demo/routes/
create : nodejs-demo/views
create : nodejs-demo/views/
install dependencies:
$ cd nodejs-demo && npm install
run the app:
$ node app
Install dependency package
~ sudo npm install
[email protected] node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
Start the program
Express server listening on port 3000
Test whether curl is successfully started
~ sudo apt-get install curl
~ curl localhost:3000
<!DOCTYPE html>
<html>
<head>
<title>Express</title>
<link rel='stylesheet' href='/stylesheets/' />
</head>
<body>
<h1>Express</h1>
<p>Welcome to Express</p>
</body>
</html>
Nodejs server log:
OK, we have successfully prepared the nodejs development environment in ubuntu. Now you can enjoy the development fun.