nvm cheatsheet

Node Version Manager (nvm) cheatsheet

With NVM: you can manage the NodeJs version with this system, so you don’t have to endure the installing and uninstalling process each time you work in a different project. There is also a NVM Windows installer.

Install a version

  • Download, compile, and install the latest release of node

    1
    nvm install node # "node" is an alias for the latest version
  • Download the latest long term support version

    1
    nvm install --lts
  • Install a specific version of node

    1
    nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
  • Uninstall a version

    1
    2
    nvm uninstall 6.14.4
    nvm uninstall --lts # uninstall the lates lts

Listing versions

If you want to see what versions are installed:

1
2
nvm ls # which version you already have installed
nvm ls-remote # which versions are available to install

Select a version

  • Set an installed version

    1
    nvm use node # set the version you just installed
  • run node for a certain installed version

    1
    2
    3
    nvm run node --version
    nvm exec 4.2 node --version
    nvm which 5.0 # get the path for the exec

System version of node

If you want to use the system-installed version of node, you can use the special default alias “system”:

1
2
nvm use system
nvm run system --version

Migrate a version

  • Install a new version of Node.js and migrate npm packages from a previous version

    1
    2
    # nvm install node --reinstall-packages-from=node
    nvm install 6 --reinstall-packages-from=5
  • Set default global packages from file while installing

If you have a list of default packages you want installed every time you install a new version, just add the package names, one per line, to the file $NVM_DIR/default-packages.

1
2
3
# $NVM_DIR/default-packages
eslint
gulp

Update npm

This is a good practice.

1
nvm install-latest-npm