What is the difference between "npm update -g", "npm upgrade -g", "npm install -g npm" and "n stable"?

My npm looks deprecated, so it seems that I can use 4 ways to update it:

sudo npm update -g # => npm 3.8.6 sudo npm upgrade -g # => npm 3.8.7 sudo npm install -g npm sudo npm cache clean -f && sudo npm install -gn && sudo n stable 

some method is higher than the installed npm 3.8.6, and some are installed 3.8.7, and the latter with n installed 3.8.3.

What are the differences between these methods and is there a standard / official way to do this?

(the difference between 3.8.6 and 3.8.7 was on my Macbook 12-inch Retina with El Capitan. This was not the case on my Macbook Pro with Mavericks)

+5
source share
1 answer

What do these commands do:

  • sudo npm update -g - this command updates all installed global packages to the latest versions.
  • sudo npm upgrade -g is an alias for the update command.
  • sudo npm install -g npm - sudo npm install -g npm latest available version of the npm package.
  • sudo npm cache clean -f && sudo npm install -gn && sudo n stable - flushes npm cache, installs n (node ​​version manager) and the latest available node.js and npm.

So, if you need to upgrade npm only to the latest version, use sudo npm install -g npm , if you want to upgrade both node and npm, use sudo npm cache clean -f && sudo npm install -gn && sudo n stable .

+8
source

Source: https://habr.com/ru/post/1247275/


All Articles