To install nodejs in your Ubuntu you have follow the following command.
sudo apt install nodejs -y sudo npm i -g n sudo n latest # or sudo n lts if you want to install LTS version.
If you get permission issue while executing this command than execute the following command. Using chown command, we are providing proper permission to the logged-in user. Update the folder path if it is different
sudo chown -R $USER /usr/local/lib/node_modules/n/bin/n #Or in older version #sudo chown -R $USER /usr/local/lib/node_modules