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

Installing Node.js / npm under Ubuntu with nvm

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.

DigitalOcean has a HOWTO for installing nvm on Ubuntu that I recommend.

Installing yarn with nvm

The yarn package 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:

Copy
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 sudo apt-get update && sudo apt-get install --no-install-recommends yarn

See also this card.

Migrating an apt-installed Node.js to nvm

Uninstall the nodejs package:

Copy
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

Configuration in the ~/.bashrc

In case you see an error like:

Copy
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:

Copy
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # 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)"

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Henning Koch
Last edit:
28 days ago
by Emanuel De
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 cookies to improve usability and analyze traffic.
Accept or learn more