NVM

Page content

What’s nvm

  • Node.js Version Manager.
  • Like pyenv in Python.
  • One difference from Pyenv is, you can’t label a name to the environment. package.json manage the libraries.

Install

Follow the official document.

https://github.com/nvm-sh/nvm

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

..... (simple results)

Check.

$ nvm --version
0.39.0
$ node
Command 'node' not found, but can be installed with:
sudo apt install nodejs

Install Node.js and switch versions

# Current available Node.js on the local machine
nvm ls

# List all available versions
nvm ls-remote

# Use latest version
nvm install node # "node" is an alias for the latest version
nvm use node

# Use speccific version
nvm install 14.0.0
nvm use 14.0.0

# set default version
nvm alias default 15.13.0

Delete a Node.js environment

Just delete the folder $HOME/.nvm/versions/node/{{ version_you_want_to_delete}}

NPM

By default, packages are managed locally (directory with package.json).

Delete packages

https://docs.npmjs.com/uninstalling-packages-and-dependencies

npm uninstall {{ package_name }}

You can find global packages in $HOME/.nvm/versions/node/lib/node_modules/. With -g option, the npm uninstall command delete from the directory.

Uninstall nvm

Just remove the directory:

rm -rf ~/.nvm