How to Set Up and Install Node.js
Updated by Linode
Node.js can be installed and maintained multiple ways across the various platforms offered. Multiple releases of Node.js are available, along with multiple versions within the LTS branch. The decision about which of these versions to install can quickly become confusing, so this guide lists the main choices for installing Node.js on Linux, and some basic reasons why you may or may not want to use a certain method.
Linux Distro Repositories
Your distro’s repos will likely contain an LTS release of Node.js. This is a good solution if:
You won’t need newer features.
You want the distro’s package manager to handle core updates.
You want to easily maintain uniformity among multiple Node.js servers.
NPM (Node Package Manager) is included with installations of Node.js by other methods, but not here;
npm is a separate package from
nodejs and must be installed separately.
Node.js from the distro’s repositories in Debian 7 or 8, or Ubuntu 12.04 or 14.04 confict with the Amateur Packet Radio Node program. In this scenario, calling Node.js requires that you use the command
nodejs -$optioninstead of the standard
node -$option. One workaround is to install the package
nodejs-legacy, which maintains a symlink from
/usr/bin/nodejsso the normal
nodecommands can be used.
The NodeSource repository is a continuation and expansion of Chris Lea’s Node.js Ubuntu PPA to offer both
.rpm binaries for various Node.js release stages. This is the option mentioned on nodejs.org for those who would like to install using the operating system’s package manager, and will generally provide more up-to-date packages than the distro’s repositories.
Node Version Manager
NVM is a separate project from Node.js and is one of the more common installation methods. NVM is installed using an installation script and it’s primary benefit is easy management of Node.js versions, including updating to newer releases and migrating your Node packages.
Official Binary Installer
Build from Source
Compiling from source code is the most advanced installation method, though it can be a remarkably simple process. Installing from source can add flexibility with compiling flags and ensures that you have the absolute latest code base at the time of installation.
Node Package Manager (NPM)
A typical installation of Node.js includes the Node Package Manager (NPM). However, an exception is any Linux-distro-supplied version of Nodejs which would need the package
npm installed. NPM is a package manager for Nodejs packages in the NPM repository. You can find extensive NPM documentation at npmjs.com.
Making a Quick Decision (the tl:dr)
Still not sure which installation method to use? Then NVM will probably be your best choice to start with. NVM faciliates easy installation and maintenance of Node.js and NPM, presents no naming issues with other software, and easily manages multple installations of Node.js that can test your application before you push a Node.js update into your production environment.
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This guide is published under a CC BY-ND 4.0 license.