Using shell script to quickly build the Nodejs development environment under Ubuntu _linux Shell

Source: Internet
Author: User
Tags install mongodb mongodb install node node server git clone

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:
$ CD ~/
$ nano-w node.sh

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

Related Article

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.