Share

Snaps are containerized software packages designed to work across cloud, desktop, and IoT devices. They work natively on most popular Linux distributions, feature automatic updates for users, improved security, and greater flexibility for developers working in Linux environments. Their auto-updating and transactional nature is making snaps a popular choice for the delivery of desktop applications in particular.

The Node.js snap contains the Node.js runtime, along the two most widely-used package managers, npm and Yarn. So with a single command, developers can be up and running with their chosen version(s) of Node.js and supporting tools with no need for external repos or personal package archives (PPAs).

TL;DR: Show me the Install!

If you are using a Linux distribution that already has snapd installed, such as Ubuntu 16.04 or later, simply run:

sudo snap install node --classic --channel=8

This will install the most recent LTS version of Node.js (Carbon).

Quick Guide

Step 1: Install snapd

snapd is the service that runs and manages snaps for you, including performing automatic updates. Installation instructions and supported versioning information for each of the following Linux distributions can be found here.

Supported Linux distributions for snapd:

Arch Linux

Debian

Fedora

Linux Mint

Manjaro

OpenEmbedded/Yocto

OpenWrt

Solus

Ubuntu

Step 2: Install a Stable Version of Node.js

To install Node.js Carbon, the most recent LTS version, run:

sudo snap install node --classic --channel=8

The --classic argument is required here as Node.js needs full access to your system in order to be useful, therefore it needs snap’s “classic confinement”. By default, snaps are much more restricted in their ability to access your disk and network, and must request special access from you where they need it.

Since you must select a Node.js major version, (e.g. 6, 8, 9 or 10), you must supply the --channel argument. Without it, snap doesn’t know which version of Node.js you want.To make sure you don’t have a disruptive change automatically installed when a new major version is released—such as Node 9 to 10—NodeSource isn’t publishing an un-versioned Node.js to the snap store.

Step 3: Confirm Installation

Run the following command to make sure node is now available on your system:

node -v

You will also find npm and yarn on your system, too!

npm -v yarn -v

Step 4: Updating and Versioning

Snaps are auto-updating. You will normally have a new Node.js installed for you on the same day of its release on nodejs.org.

Different Node.js versions live on different channels. For Node.js, the channel names are the major-version number of Node.js. To switch between Node.js channels, the refresh command takes a --channel argument.

For example, to switch to Node.js 9, run:

sudo snap refresh node --channel=9

A Note on Deployment

Due to their auto-updating nature, snaps are not necessarily appropriate for the deployment of your Node.js applications to production. NodeSource recommends a stable and integration-tested deployment pipeline for your Enterprise applications, and the NodeSource Linux distributions are an ideal source of stable Node.js binaries. However, snaps represent an excellent way to keep developer machines updated and allow for trivial and convenient switching between Node.js versions.

Ready to unleash your app in production? Read this next Running Your Node.js Application with systemd

Work with Bleeding-edge Node.js

Users feeling adventurous or interested in testing the latest code from the Node.js core developers can install from the edge” channel. This has an element of risk: it is a direct pipeline from the upstream Node.js git repository to the snap store, and previews the ongoing Node.js 10 development work. This is only recommend for those users who are willing to participate in testing and bug reporting upstream:

sudo snap install node --classic --channel=edge

A Little More About snaps

Snaps are not just a fancy new Linux package format, in fact, they are not even intended to replace the traditional role of apt , yum , dnf , pkg and friends. They are a sophisticated way to safely deliver complex applications to almost any flavor of Linux desktop.

To find out more about snaps security features, transactions and much more, start with man snap or read Canonical’s advanced snap usage tutorial. There’s also plenty of additional snaps for your Linux desktop available in the snap store such as vscode, atom, slack and spotify.

Let us know what you think of the Node.js snap over on GitHub.

One Last Thing

Node.js has distinguished itself as one of the fastest application platforms available, with one of the lowest barriers to entry for onboarding new and existing teams.

Whether modernizing legacy systems, or aiming to leverage performant, scalable solutions right out of the gate, Node.js has proven to be efficient and scalable for projects and companies of all sizes.

Check out our most recent white paper, Best Practices for Operationalizing Node.js, for a holistic view of what it takes to securely and performantly scale your Node.js applications.