Appendix A. Installing Node

This appendix provides more details on installing Node.js. If you’re fairly new to Node, we recommend installing it with a prebuilt package. We explain this for each major operating system.

Depending on your requirements, you can install Node in other ways instead. If you’re more experienced with Node or have specific DevOps requirements, skip ahead to review other ways you can install Node.

A.1. Installing Node by using an installer

Node has two installers and several prebuilt binary packages. If you use macOS or Windows, you can use either binaries or installers. The binary packages contain executable files, but the installers have installation wizards that help you put Node on your system in a place that’s easy to find when you’re running commands such as node or npm in the terminal.

If you’re new to Node, use an installer. All of the versions can be found on Node’s website under Downloads (https://nodejs.org/en/download/).

A.1.1. The macOS installer

For macOS, download the 64-bit .pkg file from Node’s website (https://nodejs.org/en/download/). You can use either the LTS or Current release. You should see a package file, as shown in figure A.1.

Figure A.1. The installer .pkg file

After you’ve downloaded the installer, double-click it to open the installation wizard (Figure A.2).

Figure A.2. The installation wizard

Click the Continue button and follow the instructions; the default options will install Node correctly. After the installation process has finished, you should be able to open a terminal and type node to run the Node REPL. Figure A.3 shows what this should look like.

Figure A.3. Node’s REPL

The next section includes the same instructions for Windows users.

A.1.2. The Windows installer

On the Node Downloads page (https://nodejs.org/en/download/), click the Windows Installer icon, or click the Windows Installer .msi link. There are 32- and 64-bit options, but you probably want 64-bit. After the file has downloaded, double-click it to run the installation wizard, shown in figure A.4.

Figure A.4. The Windows .msi installer

Accept all of the default options, and then open cmd.exe to try out the Node REPL. Figure A.5 shows Node’s REPL in Windows.

Figure A.5. Node’s REPL in Windows

If you don’t usually install software this way or don’t want to install Node systemwide, continue reading to see how else Node can be installed.

A.2. Using other ways to install Node

You can install Node from source, through your operating system’s package manager, or by using a Node version manager. If you install it from source, you’ll need a working build system and Python installed.

A.2.1. Installing Node from source

You can download Node’s source from the nodejs.org downloads page, but it’s also available via Git on GitHub (https://github.com/nodejs/node). The full build guide is also on GitHub under node/Building.md (https://github.com/nodejs/node/blob/master/BUILDING.md). You’ll need the following prerequisites to build Node:

When your build tools are ready, you can run ./configure and make in UNIX-like operating systems. In Windows, you can run .\vcbuild nosign.

A.2.2. Installing Node with a package manager

If you use Linux or macOS, you may want to install Node with a package manager. This can make it easier to update Node. For example, if you’re using a Linux web server, you might want to install Node so that it gets automatic security updates.

Node’s website has a large list of installation instructions for operating systems that provide Node as a package (https://nodejs.org/en/download/package-manager/). In Debian and Ubuntu-based systems, for example, you can get Node from the NodeSource binary distribution repository. This has its own repository on GitHub with more details (https://github.com/nodesource/distributions).

In macOS, you can install Node with Homebrew (http://brew.sh/). If you have Homebrew installed, you just need to run brew install node.

Node is also available from Docker Hub. If you add FROM node:argon to your Dockerfile, you’ll get the LTS version of Node installed into your image.