We'll install a recent version of Node.js using nvm. We'll also install Yarn 1.x package manager alongside the standard npm CLI.
-
Install nvm using Git:
cd ~/ git clone https://github.com/nvm-sh/nvm.git .nvm cd ~/.nvm git checkout v0.39.5
-
Add the following at the end of your
~/.bashrc
:### # nvm # source: https://github.com/nvm-sh/nvm#git-install ### 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 ### # yarn global symlinks directory (yarn global bin) # see https://classic.yarnpkg.com/en/docs/cli/global ### # export PATH="$(yarn global bin):$PATH" # to speed things up, inline the path directly: export PATH="$HOME/.yarn/bin:$PATH"
-
Restart your terminal. Verify nvm works (should print something like
0.39.5
):nvm -v
-
Install the latest Node.js 20:
nvm install 20.*
-
Verify Node.js is installed and active (should print something like
v20.6.1
):node -v
-
Upgrade bundled npm and install yarn:
npm --global install npm yarn
-
Check the installed versions:
npm -v yarn -v
-
Set yarn prefix for global bins (it's the default, but to be future-proof):
yarn config set prefix ~/.yarn
-
Install some useful global packages using Yarn:
yarn global add node-gyp nodemon sort-package-json doctoc
-
Verify that Yarn global packages binaries are on your PATH (should print
3.0.1
):nodemon -v
That's all!