https://github.com/creationix/nvm#installation
- https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04
- https://medium.com/@brianmayrose/installing-node-version-manager-nvm-and-nodejs-on-ubuntu-16-04-b370c8d9e0cf
Get NVM (package) version
nvm --version
List all locally installed versions
nvm ls
List all available versions to install
nvm ls-remote
Install specific version
nvm install <NODE_VERSION>
// nvm install 8.11.0
Check current node installed
nvm current
node -v
Check where the current node version points to
which node
which npm
npm root -g
- In Ubuntu it returns:
/home/<USERNAME>/.nvm/versions/node/v8.11.0/bin/node
/home/<USERNAME>/.nvm/versions/node/v8.11.0/bin/npm
/home/<USERNAME>/.nvm/versions/node/v8.11.1/lib/node_modules
If you have multiple installed versions of node, you can switch between them using
nvm use <NODE_VERSION>
Update from <OLD_NODE_VERSION> to <NEW_NODE_VERSION> (and reinstall all your global packages !)
nvm install <NEW_NODE_VERSION> --reinstall-packages-from=<OLD_NODE_VERSION>
// nvm install 8.11.1 --reinstall-packages-from=8.11.0
You can now uninstall the old version (e.g. 8.11.0)
nvm uninstall 8.11.0
Watch out to update the default
alias if needed
nvm alias default 8.11.1
You want to used a globally-installed (-g
) package in your Node REPL, but the require() commands returns Error: Cannot find module
?
For the current shell
export NODE_PATH=$NODE_PATH:`npm root -g`
For all shell when opened (source)
// copy the line to your ~/.bashrc file (below the 3 lines concerning NVM_DIR)
export NODE_PATH=$NODE_PATH:`npm root -g`
Also note that NVM not updating the $NODE_PATH is intentional
Check that $NODE_PATH is correct
echo $NODE_PATH
- in Ubuntu it returns:
:/home/<USERNAME>/.nvm/versions/node/v8.11.1/lib/node_modules