Nodejs is really very hot, before the past, but never seriously recorded anything. Build its development environment under Ubuntu Try a quick, easy way to get the system to automatically help you install what you need, and we'll generate a shell script to do the following:
Install git under the latest Node,node Package Manager, Forever and Cloud9ide tools (optional), MongoDB 10gen;
Note: The script's normal operation needs to be compared to the new version of Ubuntu, and it needs to be networked because it will connect to the network to download all the dependent-package sequential installations.
1. Scripting code:
Copy Code code as follows:
#!/bin/sh
Echo ' System Update '
Apt-get Update
Echo ' Update completed '
Apt-get Install Libssl-dev git-core pkg-config build-essential
Echo ' Clone node.js '
Cd/usr/src
git clone https://github.com/joyent/node
Echo ' Node.js clone completed '
Echo ' Install node.js '
CD node
./configure && make && make install
Echo ' Node.js install completed '
Echo ' Install Node Package Manager '
Curl Http://npmjs.org/install.sh | Sh
Echo ' NPM install completed '
Echo ' Install Forever '
NPM Install Forever
Echo ' Forever install completed '
Echo ' Install cloud9ide '
git clone git://github.com/ajaxorg/cloud9.git
Echo ' Cloud9ide install completed '
Echo ' Install MongoDB '
sudo apt-key adv--keyserver keyserver.ubuntu.com--recv 7F0CEB10
echo "Deb Http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >>/etc/apt/sources.list
sudo apt-key adv--keyserver keyserver.ubuntu.com--recv 7F0CEB10
sudo apt-get update
sudo apt-get install Mongodb-10gen
Echo ' MongoDB install completed. '
2. Save script to file:
Copy Code code as follows:
Paste the above code into the node.sh file, Ctrl+o Save, Ctrl+x exit the Nano. If you have not installed the Nano, please Google install it.
3. Execute script:
Copy Code code as follows:
$ chmod a+x node.sh && sudo./node.sh
After you've installed it, check the node version: Node-v, and test for successful installation.
4. Establish the test:
Copy Code code as follows:
mkdir Node_project
CD Node_project
Nano-w Server.js
The following is the famous Nodejs server code:
Copy Code code as follows:
var http = require (' http ');
Http.createserver (function (req, res) {
Res.writehead ({' Content-type ': ' Text/plain '});
Res.end (' Hello world\n ');
}). Listen (1337, "127.0.0.1");
Console.log (' Server running at http://127.0.0.1:1337/');
Run Code: Node Server.js
Open in Browser: http://127.0.0.1:1337