How to install nodejs in ubuntu

Source: Internet
Author: User
Tags curl git clone

Installation method 1

Install dependency packages

The code is as follows: Copy code

$ Sudo apt-get install g ++ curl libssl-dev apache2-utils python build-essential gcc

Download and Install

Note the installation version

The code is as follows: Copy code

// Download
$ Wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz

// Extract:
$ Tar-zxf node-v0.10.14.tar.gz $ cd node-v0.10.14

// Default installation: (in the home directory by default)
$./Configure $ make $ sudo make install

// Select the directory for installation (install nodejs in the/usr/local/node directory)

$./Configure-prefix =/usr/local/node
$ Make
$ Sudo make install

Method 2

Step 1: install the dependency package
 

The code is as follows: Copy code
// Install the compiler and runtime environment
Sudo apt-get install g ++ curl libssl-dev apache2-utils

 
// Install git. If you download the source code directly, you can skip it.
Sudo apt-get install git-core

Step 2: obtain the node source code

1) go to the official website Direct Download: http://nodejs.org/#download node-v0.6.5.tar.gz
 

The code is as follows: Copy code
// Extract
Tar-zxf node-v0.6.5.tar.gz
// Enter the decompressed folder
Cd node-v0.6.5

2) git clone git: // github.com/joyent/node.git

 

The code is as follows: Copy code
# Specify the version to be migrated out. If the version is not migrated out, the latest version will be installed.
Git checkout v0.6.5
# Enter the node folder
Cd node

Step 3: compile and install

1) do not specify the installation path in three steps

 

The code is as follows: Copy code

./Configure
Make (takes several minutes)
Sudo make install

2) specify the installation path and install it in the/opt/node Directory. After installation, you must grant the permission to opt/node. Otherwise, the installation will fail.

The code is as follows: Copy code
 
./Configure -- prefix =/opt/node
Make
Sudo make install

Step 4: set environment variables

The code is as follows: Copy code

// If no environment variable is set, you can only run node in the bin directory
Export PATH = $ PATH:/opt/node/bin

Step 5: test whether the node is successfully installed

The code is as follows: Copy code

 
// The node version number is displayed, indicating that the installation is successful.
Node-v

Step 6: install npm
 

The code is as follows: Copy code
// Get it done in one sentence
Curl http://npmjs.org/install.sh | sh
// If it fails
Curl http://npmjs.org/install.sh | sudo sh

Step 6: install express
 

The code is as follows: Copy code
# Remember to add-gd. Otherwise, it will be installed in the current folder.
Npm install express-gd
#-G indicates to install it in the lib of NODE_PATH, and-d indicates to install dependency suites together. If?] If there is-g, the current directory will be installed (a node_modules folder will be created). You can compare the differences between the two through the following commands:
Npm list-g
Npm list

Step 7: Test express

The code is as follows: Copy code
/Enter your working directory
// Create a testapp application
Express testapp
Cd testapp
Node app. js

All installed. Now you can enter the Node. Js fantasy world !!

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.