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).)
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.
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.
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.
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 for update
command.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, 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With