Preliminaries
In this tutorial, we’ll show you how to get up and running with node.js. If you’re used to developing on the front-end in JavaScript, you’ll be glad to hear you can translate much of that knowledge to begin developing the backend. Node.js is an asynchronous, event-driven runtime environment that works well for applications that require fast I/O. As a result, node applications have high throughput and are highly scalable. Let’s get started.
Note that if you require a version of node greater than v0.10.25, you will have to install it via a personal package archive (PPA). We’ve outlined the steps for that process further below.
Installing from Default Package Repositories
First, we should update Ubuntu’s package repositories to make sure we’re getting the latest stable version of node available to us.
sudo apt-get update
Now we can update the node.js package which is located in the Ubuntu repositories
sudo apt-get install nodejs
After this process is complete, check that everything proceeded correctly by prompting the node.js package for the version number
nodejs --version v0.10.25
That’s it — you’re ready to start developing in node.js!
Installing npm
The node.js package installs the runtime environment for all the standard modules outlined in the node.js documentation. However, if you’d like access to a large number of additional modules you can install node package manager or npm. If you’ve used Python’s pip or Ruby’s bundler, you won’t feel out of place. Install npm by running the following command
sudo apt-get install npm
That’s it! Enter npm --help to get a list of commands you can use with npm.
Install node.js via PPA
Ubuntu’s default package repositories don’t always contain the latest version of the packages it advertises. We’ll add a third-party package repository in order to install a newer version of node.js. Run the following command:
sudo add-apt-repository ppa:chris-lea/node.js
You’ll be prompted to press enter to add the repository or press CTRL-C to cancel. Press enter. Now we need to update the aptitude package repositories to become aware of the newly available packages from the repository we just added.
sudo apt-get update
Finally, we can install node.js as normal:
sudo apt-get install nodejs
If you want access to the thousands of packages available on the node package repositories, you should install npm along with node.js.
sudo apt-get install npm
Final Words
Congratulations! You’re all set to write Javascript on the server side and develop blazing fast I/O applications. Check our our Community Section on more resources on how to perform various server administration and DevOps tasks. From all of us at Stack Harbor, ahoy!
