What those commands do:
sudo npm update -g– this command updates all installed global packages to the the latest versions.sudo npm upgrade -g– it’s an alias forupdatecommand.sudo npm install -g npm– installs the latest available version of npm package.sudo npm cache clean -f && sudo npm install -g n && sudo n stable– cleans the npm cache, installsn(node version manager) and the latest available node.js and npm.
So, if you need update npm to the latest version only, use sudo npm install -g npm, if you want to update and node and npm, use sudo npm cache clean -f && sudo npm install -g n && sudo n stable.