You can follow one of the following options to install NodeJS in Ubuntu OS, I would suggest follow the first option 2 if you want NodeJs on Your local dev machine or development server.
If you are installing it on your production server then I guess the Option 1 is better way to go.
Option 1: Installing Node.js with Apt Using a NodeSource BASH
apt update 
cd ~
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &&\
sudo apt-get install -y nodejsThe NodeJS is ready to use you can verify installation by using node -v and npm -v
you should get the latest LTS version installed.
Option 2: Installing Node Using the Node Version Manager
To install NVM using curl, run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashalternatively, you can also install NVM using wget, run the following command:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashSource the new instructions NVM added to .bashrc
source ~/.bashrcYou have successfully installed NVM on your machine, to install the latest version of Node, run the following:
nvm install nodeNow, you can ask NVM which versions of Node are available:
nvm list-remoteYou can install your preferred version from list using following command
nvm install _your_preferred_version_of_nodejsReview all installed versions of Node with the ls command.
nvm lsMore information about Node NVM Also learn more about NodeSource
