Install nodejs using NVM

Install nodejs using NVM

Here is the official github repo of NVM: https://github.com/nvm-sh/nvm
Follow the document, you can use code below to install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
You probably need to reopen the terminal to make nvm working.
Check nvm version
nvm --version
Get installed node version
nvm ls
Get node version from server
nvm ls-remote
Get LTS node version from server
nvm ls-remote | grep LTS
Install node
nvm install v18.16.1 nvm install 18
Note: to support higher version node, you may need to upgrade you linux server, CentOS7 currently only support node version < 18
nvm install v16.20.1 nvm install 16
To uninstall node
nvm uninstall 18
To switch node version
nvm use v16.20.1 nvm use 16
To find out where nvm manage all node versions
which node or whereis node
You will see something like this, path:
/root/.nvm/versions/node/v16.20.1/bin/node