There are different way of updating the Node.js, but the best way of updating Node.js on Ubundu server is to use NVM (Node Version Manager).
First update the package repository with the command:
sudo apt update
Now install NVM using curl command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
In order to verify the nvm version, close and reopen the terminal or run following command
Verify if you have successfully installed NVM:
In order to list the available releases run following command:
To install the latest version, use the
nvm command with the specific Node.js version:
nvm install [version number]
Since now we have installed two different versions of node 14 & 15, there is a nvm command that can be used to switch in between node versions.
node use 15
That’s it, this is how you can manage and update multiple node versions, by the way same can be done on Mac IOS.