Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

My npm seems out of date, so it seems I could use four different 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 -g n && sudo n stable 

Some of the methods above installed npm 3.8.6, some installed 3.8.7, and the last one by n installed 3.8.3.

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

(The 3.8.6 and 3.8.7 difference was on my MacBook 12 inch Retina with Mac OS X v10.11 (El Capitan). It wasn't so on my MacBook Pro with Mac OS X v10.9 (Mavericks).)

like image 363
nonopolarity Avatar asked Apr 16 '16 19:04

nonopolarity


People also ask

What is the difference between npm install and npm update?

The npm install installs all modules that are listed on package. json file and their dependencies. npm update updates all packages in the node_modules directory and their dependencies.

What does npm install G mean?

npm install -g. the -g flag is a shorthand for the global configuration which sets the package install location to the folder where you installed NodeJS. This is useful when you need to run the package from the command line instead of using require() and import it to your code.

Does upgrading node upgrade npm?

The required packages and modules in the Node project are installed using NPM. The update of the NPM means the update node package manager to the latest version. The update of NPM updates the Node. js and modules to the latest version.


1 Answers

What those commands do:

  1. sudo npm update -g - this command updates all installed global packages to the the latest versions.
  2. sudo npm upgrade -g - it's an alias for update command.
  3. sudo npm install -g npm - installs the latest available version of npm package.
  4. sudo npm cache clean -f && sudo npm install -g n && sudo n stable - cleans the npm cache, installs n (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.

like image 86
alexmac Avatar answered Oct 13 '22 21:10

alexmac