Today, i will explain you how to use NodeJS and NPM with NVM on a Ubuntu machine.
To install or update nvm, you should run the install script. To do that, you can use the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
The script clones the nvm repository to ~/.nvm
, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile
, ~/.zshrc
, ~/.profile
, or ~/.bashrc
).
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
After you put the code into the profile you have to restart the console and then you can start installing node directly.
nvm install 16
nvm use 16
And done. Now you are able to use npm and node.