Easy way to install nvm on Ubuntu
Install (Nvm — Node version manager) in 3 easy steps
As the name suggests, nvm allows you to run multiple versions of NodeJS on your PC. This is especially useful when you are working on multiple projects that require different versions of NodeJS.
Example usage:
nvm install 16.0.0 # Install node version 16.0.0
nvm use 16.0.0 # Use node version 10 (if it is installed)
nvm run 16.0 app.js # Run app.js using node version 10.0.x
# see built-in help page for more usage examples
nvm --help
Step 1: Download and install the nvm package
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
# Alternatively
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
Step 2: Configuration#
# Create an environment variable poinitng to nvm home directory
export NVM_DIR="$HOME/.nvm"
# Run nvm.sh script from the nvm home dir (IF IT EXISTS!)
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Step 3: Verify your installation#
nvm --version
# If everything worked you should get a version number printed on the console