Skip to content

Install package manager

Kevin edited this page Apr 19, 2018 · 1 revision

Before you can install the required packages we need a node package manager. The two most popular are npm and yarn so I will cover how to install them below.

Table of contents

Yarn

macOS

Homebrew

You can install Yarn through the homebrew package manager. This will also install Node.js if it not already installed.

brew install yarn

If you use nvm or similar, you should exclude installing Node.js so that nvm's version of Node.js is used.

brew install yarn --without-node

MacPorts

You can install Yarn through MacPorts. This will also install Node.js if it not already installed.

sudo port install yarn

Path Setup

If you chose manual installation, the following steps will add Yarn to path variable and run it from anywhere.

Note: your profile may be in your .profile, .bash_profile, .bashrc, .zshrc, etc.

Add this to your profile: export PATH="$PATH:/opt/yarn-[version]/bin" (the path may vary depending on where you extracted Yarn to) In the terminal, log in and log out for the changes to take effect To have access to Yarn’s executables globally, you will need to set up the PATH environment variable in your terminal. To do this, add export PATH="$PATH:yarn global bin" to your profile.

Upgrade Yarn

Yarn will warn you if a new version is available. To upgrade Yarn, you can do so with homebrew.

brew upgrade yarn

Test that Yarn is installed by running:

yarn --version

Debian / Ubuntu

On Debian or Ubuntu Linux, you can install Yarn via our Debian package repository. You will first need to configure the repository:

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

On Ubuntu 16.04 or below and Debian Stable, you will also need to configure the NodeSource repository to get a new enough version of Node.js.

Then you can simply:

sudo apt-get update && sudo apt-get install yarn

Note: Ubuntu 17.04 comes with cmdtest installed as default. If you're getting errors from installing yarn, you may want to run sudo apt remove cmdtest first. Refer to this for more information.

If you use nvm you can avoid the node installation by doing:

sudo apt-get install --no-install-recommends yarn

Note: Due to the use of nodejs instead of node name in some distros, yarnmight complain node not being installed, a workaround for this is to add an alias in your .bashrc (or similar), like som: alias nodejs=node. This will point yarn to whatever version of node you decide to use.

Test that Yarn is installed by running:

yarn --version

CentOS / Fedora / RHEL

On CentOs, Fedora and RHEL, you can install Yarn via the RPM package repository for Yarn. (Please see yarns own pages if you get any errors when adding the repository.)

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo

If you do not already have Node.js installed, you should also configure the NodeSource repository:

curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -

Then you can simply:

sudo yum install yarn
## OR ##
sudo dnf install yarn

Test that Yarn is installed by running:

yarn --version

NPM

npm is bundled with node. To check if you have npm already installed run: npm --version

macOS

Download and run the npm program pkg from nodejs.org

Manual install on unix systems

There's a pretty robust install script at https://www.npmjs.com/install.sh. You can download that and run it.
Here's how to download and run it with curl:

curl -L https://www.npmjs.com/install.sh | sh