“npm update -g"、“npm upgrade -g"、“npm install -g npm"和“n stable"之间有什么区别?
我的 npm 似乎过时了,所以我可以使用四种不同的方式来更新它:
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
上面的一些方法安装了npm 3.8.6,一些安装了3.8.7,最后一个通过n
安装了3.8.3.
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?
(3.8.6 和 3.8.7 的区别在于我的 MacBook 12 英寸 Retina 和 Mac OS Xv10.11 (El Capitan).我的 MacBook Pro 与 Mac 操作系统不同X v10.9(小牛队).
(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).)
这些命令的作用:
-
sudo npm update -g
- 此命令将所有已安装的全局包更新为最新版本. -
sudo npm upgrade -g
- 它是update
命令的别名. -
sudo npm install -g npm
- 安装最新版本的 npm 包. -
sudo npm cache clean -f &&须藤 npm install -g n &&sudo n stable
- 清理 npm 缓存,安装n
(节点版本管理器)和最新可用的 node.js 和 npm.
-
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.
所以,如果你只需要更新npm
到最新版本,使用sudo npm install -g npm
,如果你想更新node和npm,使用sudo npm cache clean -f &&须藤 npm install -g n &&sudo n 稳定.
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
.