Posted almost 7 years ago. Visible to the public. Linked content.

Installing Node.js / npm under Ubuntu with nvm (with yarn)

I recommend install Node.js using nvm. This way you can have multiple Node versions in your ~/.nvm. You also won't need to install global packages with sudo anymore.

Installing nvm

DigitalOcean has a HOWTO for installing nvm on Ubuntu ( 16.04 Archive , 18.04 Archive , 20.04 Archive ) that I recommend.

Installing yarn with nvm

The yarn package Archive depends on nodejs, but with nvm you no longer want to have that package installed through apt.

You can install yarn while skipping dependencies like this:

curl -sS | sudo apt-key add - echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get install --no-install-recommends yarn

If yarn stops updating, the imported key has expired and you need to re-run the line with apt-key add.

Migrating an apt-installed Node.js to nvm

Uninstall the nodejs package:

sudo apt remove nodejs

Check if you want to remove any custom package sources for Node.js in your /etc/apt/sources.list.d (e.g. nodelist.list).

Now install Node.js with nvm Archive

Configuration in the ~/.bashrc

In case you see an error like:

Yarn requires Node.js 4.0 or higher to be installed.

Check if command -v "node" returns a path and you load NVM before Yarn. This could look like this:

export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/" ] && \. "$NVM_DIR/" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion # Load global yarn binaries export PATH="$PATH:$(yarn global bin)"

If you want to switch the Node version automatically with a cd you can use this snippet Archive .

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Henning Koch
Last edit:
over 1 year ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more