Install node.js & npm with NVM

NVM provides a easy handling of managing the right node.js and npm versions.

It is crucial to decide what developer you are. Are you the a Windows, a Mac or Linux user?

This installation is done on user level, means not as a root-user.

Setup prerequisites

If you are a Linux user, perfect you will have the easiest path! Linux is developed by developers FOR developers. If you a Mac user it is a bit more complicated as Linux but still very easy. As a windows user? puhh it will take timeā€¦

NVM Linux installation

You will need some packages, debian based systems like Ubuntu execute. This commands require root permissions, since installed system wide.

sudo apt update
sudo apt install curl wget git

NVM Mac installation

for Mac the package installation is

brew install curl wget git

now go on with the steps of Install NVM

NVM Windows installation

Puhh, we will only briefly describe to setup on a crappy operating system for developers. Also informing you, that this path will cause many really odd issues, so it is NOT suggested to work under Windows with nvm directly.

  1. install cygwin with bash, wget, curl, git
    https://www.cygwin.com/install.html
  2. under cygwin install nvm by
    following the steps like under Linux nvm installation described

now go on with the steps of Install NVM

Install NVM

Install NVM to manage different node.js and npm versions

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

follow the instructions. Sometimes you have to manually add the following string to your bashrc or bash_profile or profile file. Check the output of the above command and execute accordingly. If it is missing use the output from the above command to add.

vi ~/.bashrc

scroll at the end check if already added, if not add

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

to use the nvm immediately in current terminal run

source ~/.bashrc

Using nvm

Now we need to install node.js and npm. We only work with LTS versions due to being more stable. So we can stick to version numbers or to LTS releases. In this example we will stick to lts/gallium which is

  • node.js v16.x
  • npm 8.19.x
nvm install lts/gallium
nvm use lts/gallium

Test the version

npm version

This should return some similar version like

{
npm: '8.19.2',
node: '16.18.0',
...
}

Also we recommend to set it as default version

nvm alias default lts/gallium

Recommended too

Install SDKMAN

Share:

Facebook
Twitter
Pinterest
LinkedIn

Leave a Comment

Your email address will not be published. Required fields are marked *

Table of Contents

On Key

Related Posts