Install Node.js on Ubuntu


Browse by products and services

  • Applies to: DV Developer
    • Difficulty: Hard
    • Time: 30
    • Tools needed: SSH Access

READ ME FIRST

This article is provided as a courtesy and is intended as a general guide. Installing, configuring, and troubleshooting third-party applications is not supported by (mt) Media Temple. Our support staff will be unable to assist you should you run into any complications installing this software. Please take a moment to review our Statement of Support.

Overview

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive, real-time applications that run across distributed devices.

Following the steps below will allow you to install Node.js and a basic application.

Installation

  • Log into your DV Developer via SSH as the root user:
    ssh root@hostname
  • We'll be using aptitude to streamline the installation of this software, so first we'll want to make sure that your server is up-to-date by running the following commands:
    root@raring:~# aptitude -y update
  • root@raring:~# aptitude -y safe-upgrade
  • Next, you'll need to install some basic libraries needed to complete the installation:
    root@raring:~# aptitude -y install dialog curl build-essential python-software-properties software-properties-common git-core
  • In this next step, we're going to add the Node.js PPA from Chris Lea:
    root@raring:~# add-apt-repository ppa:chris-lea/node.js
  • When prompted, press ENTER. Now update your sources again:
    root@raring:~# aptitude -y update
  • Now you should be able to install the nodejs package via aptitude:
    root@raring:~# aptitude -y install nodejs
  • To confirm the package was successfully installed, run the following:
    root@raring:~# node -v
  • The command should print out the most recent version number. Next, you'll want to set up a document root (if you have one already, skip this step) and get into that directory to set up your example application:
    root@raring:~# mkdir -p /var/www/nodeapp && cd $_
  • Now, clone the example repository from Github:
  • root@raring:~# git clone https://github.com/heroku/node-js-sample.git .
  • To install the application requirements, use the node package manager, npm:
  • root@raring:~# npm install
  • Once that has completed, you can start your example application:
  • root@raring:~# node web.js
  • By default, the application will be listening with port 5000. You should now be able to open your web browser and pull up your app by entering your DV Developer IP address on port 5000.