install yarn & latest node.js on linux

run all these steps as root to install nvm and node globally for all users. if you want to install node on a per-user basis, this guide is not for you, you need to modify the steps.

remove any nodejs versions installed via the packet manager of your os .. for example linux:

apt remove --purge nodejs

install the latest version of nvm. note, this will install nvm globally for all users.

export XDG_CONFIG_HOME="/opt"
curl -o-$(curl -s | grep "tag_name" | cut -d : -f 2,3 | tr -d ' ",')/ | bash
echo 'export NVM_DIR="'$XDG_CONFIG_HOME'/nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion' > /etc/profile.d/
source /etc/profile.d/

install latest version of nodejs with nvm

nvm install node 

add yarn repo (ubuntu, see yarn docs for other distros)

apt install curl gnupg2 # in case you are on a fresh and minimalistic installation, i.e. in a Dockerfile :) 
curl -sS | apt-key add -
echo "deb stable main" | tee /etc/apt/sources.list.d/yarn.list

install yarn without installing node.js from the repo..

apt update && apt install --no-install-recommends yarn
  • install_yarn_latest_node.js_on_linux.txt
  • Last modified: 13.11.2020 23:16
  • by Pascal Suter