Link Search Menu Expand Document

Set up Node and NPM

Table of contents

  1. Set up Node and NPM
    1. Install Node and NPM
      1. Node Version Manager
      2. Node Installer
      3. Ubuntu Packages
    2. Next…

Install Node and NPM

There are two primary ways to install Node: Either using a Node version manager, or by installing Node directly using an installer.

Node Version Manager

I have found that developers who are experienced with Node often appreciate the benefits of using a Node version manager. They make it easy to install, upgrade, and switch between Node versions. This is really handy when you are working on two different web apps that are using different versions of Node. Also, the NPM documentation recommends using a Node version manager instead of a Node installer, so they are worth a look.

It can be confusing if someone just tells you to “install NVM” because there are a few such Node version managers around, including one named “nvm”.

For Windows, I have used nvm-windows. There are additional options for Windows, macOS, and Linux.

Node Installer

Alternatively, If you just want to try out Node and don’t want to use a Node version manager, then you can install Node directly. This has worked fine for me on Windows. It isn’t as easy when you want to switch or upgrade Node versions, but it can get you up and running with a recent version of Node.

If you have Windows or macOS, you can download a Node installer here. Note: NPM will be installed by the Node installer.

For Ubuntu, there are several ways to install Node and NPM. The NPM documentation recommends using the NodeSource Installer.

Ubuntu Packages

Alternatively for Ubuntu, you can use the Ubuntu package repository to install Node and NPM:

sudo apt update
sudo apt install nodejs
sudo apt install npm

I recently used this method, but ran into a permissions error when trying to install global packages. It was because I didn’t have access to the location on my machine where NPM was trying to install the global packages: /usr/local/lib/node_modules.

If this happens to you, you could use sudo when you install global packages, but that might cause further permissions issues down the road. A better approach is to configure your global node_modules directory to be in a location that you have access to:

First create a folder under your home directory and configure NPM to use it.

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

Next, add ~/.npm-global/bin to your path. One way to do this is to add this line to your ~/.profile:

export PATH=~/.npm-global/bin:$PATH

Then, source your profile so that your terminal has the new path value.

source ~/.profile

Now, when you install global packages using NPM, they will reside under your home directory at ~/.npm-global. For more info on this, see the answer to this question on Stack Overflow

Next…

Set up Angular Project