Step 1 Do the usual first, i.e.
sudo apt update
sudo apt upgrade
Step 2 Make sure npm is up to date as well
npm cache clean -f npm install -g n #if not already installed sudo n stable
It might take some doing to achieve the above, as I had a few issues to deal with ion Ubuntu 20..04 Firstly I had to update npm and node :
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt-get install -y nodejs
Then I had to change the permissions on the node modules directory
sudo chown -R $USER /usr/local/lib/node_modules
Only then could I get sudo npm install -g to work as intended.