Normally you have tried:
sudo apt remove nodejs
sudo apt remove npmsudo apt install nodejs
sudo apt install npm
It didn’t work. You have also tried:
npm install npm@latest -g
It prompted the error again. You have also tried:
curl https://www.npmjs.com/install.sh | sudo sh
It didn’t work.
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
It will work.
Read more at this https://github.com/nodesource/distributions/blob/master/README.md#deb