My npm seems out of date, so it seems I could 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 -g n && sudo n stable
some method above installed npm 3.8.6, and 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 El Capitan. It wasn't so on my Macbook Pro with Mavericks)
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 forupdate
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, installsn
(node version manager) and the latest available node.js and npm.So, if you need update
npm
to the latest version only, usesudo npm install -g npm
, if you want to update and node and npm, usesudo npm cache clean -f && sudo npm install -g n && sudo n stable
.