Node.js installation guide

26th of September, 2017 in guide

NodeJS Installation guide

  1. NVM
    1. Installation
    2. Usagee
  2. NPM
    1. Installation
    2. Proxy setup
  3. YARN
    1. Installation
      1. Add repository
      2. Install with apt-get
    2. Usage
      1. Starting a new project
      2. Adding a dependency
      3. Adding a dependency to a specific category
      4. Upgrading a dependency
      5. Removing a dependency
      6. Installing all the dependencies of a project
      7. Global action on a package
      8. Force Yarn to use https on github repositories

NVM

Installation

1
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash

Restart the terminal.

Usagee

1
2
3
4
5
6
7
nvm install node              # Install the latest version of node
 
nvm install 4.2.2             # Install v4.2.2 of node
 
nvm use node                  # Use latest version of node
 
nvm exec 4.2 node --version   # Subshell command

NPM

Installation

1
2
3
which node                        # Get node's path.
cd .nvm/versions/node/v8.5.0/lib/ # Navigate to the above path 
npm install npm                   # Install NPM

Proxy setup

1
2
npm config set proxy http://user:pwd@host:port
npm config set https-proxy http://user:pwd@host:port

YARN

Installation

Add repository

1
2
3
4
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
> OK
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
> deb https://dl.yarnpkg.com/debian/ stable main

Install with apt-get

1
2
apt-get update
apt-get install yarn

Usage

Starting a new project

1
yarn init

Adding a dependency

1
2
3
yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

Adding a dependency to a specific category

1
2
3
yarn add [package] --dev
yarn add [package] --peer 
yarn add [package] --optional

Upgrading a dependency

1
2
3
yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

Removing a dependency

1
yarn remove [package]

Installing all the dependencies of a project

1
yarn

Global action on a package

1
yarn global <ACTION> [package]

Global packages are installed in yarn global bin location.
That location may be added to the PATH environment variable.

Force Yarn to use https on github repositories

1
2
3
4
5
# Fails
yarn add @angular/cli

# Works
yarn add git+https://github.com/angular/angular-cli

 
Graphic logo for Node.js software from nodejs.org/en/about/resources/