Install nodejs under Ubuntu 11.10

Source: Internet
Author: User
Step 1: Install the dependency package

1. Install Python version 2.6 or later (Ubuntu has been installed by default. You can use the pyhton-V command in terminal to view the Python version ). In Python 11.10, The Python version is 2.7.2 +.

My system displays:

Python 2.7.2 + (default, Oct 4 2011, 20:03:08)

2. install other dependency packages:
Sudo apt-Get install g ++ curl libssl-dev apache2-utils
3. Install the GIT tool:
Sudo apt-Get install Git-core
Step 2: Obtain the source code

Git clone git: // github.com/joyent/node.git
Wait until the download is completed. The size is 20 + M.
Step 3: Specify the compilation version, which is important!

1. First enter the folder for storing the downloaded source code (my current file directory is/home/jackqqxu /):

CD Node

2. Specify the migrated version:
Git checkout v0.6.8 (refer to: http://nodejs.org/dist)

node-v0.6.8.tar.gz 

This is very important. Some of the latest versions may cause NPM to be unable to download the corresponding package.

3. Specify the path for compilation and execution:
Mkdir ~ /Local
./Configure-Prefix = $ home/local/node
Make
Make install
Echo 'export Path = $ home/local/node/bin: $ path'> ~ /. Profile
Echo 'export node_path = $ home/local/node: $ home/local/node/lib/node_modules '> ~ /. Profile
Source ~ /. Profile
Step 4: Set Environment Variables

If you want to continue using the node command after the restart, you need to set the environment variable:
Run sudo gedit/etc/profile to open the configuration file. Add the following two lines at the end of the file:
Export Path = "$ home/local/node/bin: $ path"
Export node_path = "$ home/local/node: $ home/local/node/lib/node_modules"
Save and restart the system to make the settings take effect. Of course, you can also log out of the user here.
Step 5: Install NPM

Curl http://npmjs.org/install.sh | sh
Install the corresponding package as needed, such as express:
NPM install Express
If the command does not respond for a long time after it is entered, you can view the detailed execution information by adding the-verbose parameter, that is:
NPM install express-verbose
Generally, downloading fails for two reasons:
1. The network speed is too slow and exits upon timeout.
2. the node version is too new, and the downloaded package is not supported. (The solution is described in step 3 .)
Step 6: test the helloworld Program

Save the following code as a hello. js file.

1

2

3

4

5

6

var
http = require(
'http'
);

http.createServer(
function
(req, res) {

  
res.writeHead(200, {
'Content-Type'
: 
'text/plain'
});

  
res.end(
'Hello Node.jsn'
);

}).listen(8124, 
"127.0.0.1"
);

console.log(
'Server running at http://127.0.0.1:8124/'
);

Then run the following command:
Node hello. js
Start the service.
Open your browser and enter the address: http: // 127.0.0.1: 8124/

If Hello node. jsn is returned, the installation is successful! The effect is as follows:

I hope it will be useful to you. I have tested it myself.

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.