如何将 NPM 从 1.x 升级到 2.x?
How to upgrade NPM from 1.x to 2.x?
我是 运行 windows 7,当我安装 node.js 时,它附带了 NPM 1.4.3。我需要 NPM 2.0.2,所以我 运行 以下内容;
C:\proj>npm install -g npm@2.0.2
npm http GET http://localhost:8000/nexus/content/groups/npm-all/npm/2.0.2
npm http 200 http://localhost:8000/nexus/content/groups/npm-all/npm/2.0.2
npm http GET http://localhost:8000/nexus/content/groups/npm-all/npm/-/npm-2.0.2.tgz
npm http 200 http://localhost:8000/nexus/content/groups/npm-all/npm/-/npm-2.0.2.tgz
C:\Users\pgreen\AppData\Roaming\npm\npm -> C:\Users\pgreen\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm@2.0.2 C:\Users\pgreen\AppData\Roaming\npm\node_modules\npm
输出确实显示我正在使用本地 nexus 插件来执行 NPM 存储库代理,但我没有理由怀疑这会导致任何问题。
安装后我看到:
C:\proj>npm --version
1.4.3
那么我缺少什么才能在命令行上使用 npm 2.0.2 版?
我只需要 RTFM:
Upgrading on Windows
By default, npm is installed alongside node in C:\Program Files
(x86)\nodejs. npm's globally installed packages (including,
potentially, npm itself) are stored separately in a user-specific
directory (which is currently
C:\Users\AppData\Roaming\npm). Because the installer puts
C:\Program Files (x86)\nodejs before
C:\Users\AppData\Roaming\npm on your PATH, it will always
use version of npm installed with node instead of the version of npm
you installed using npm -g install npm@. To get around this,
you can do one of the following:
Option 1: edit your Windows installation's PATH to put C:\Users\<username>\AppData\Roaming\npm before C:\Program Files
(x86)\nodejs. Remember that you'll need to restart cmd.exe (and
potentially restart Windows) when you make changes to PATH or how npm
is installed.
Option 2: remove both of
C:\Program Files (x86)\nodejs\npm
C:\Program Files (x86)\nodejs\npm.cmd
Option 3: navigate to C:\Program Files (x86)\nodejs with cmd.exe and then run the installation without -g:
npm install npm
If you installed npm with the node.js installer, after doing one of
the previous steps go into C:\Program Files\nodejs\node_modules\npm
and copy the file named npmrc in the new npm folder, which should be
C:\Users\AppData\Roaming\npm\node_modules\npm. This will
tell the new npm where the global installed packages are. See the
point below for more details.
(See also the point below if you're running Windows 7 and don't have
the directory C:\Users\AppData\Roaming\npm.)
我是 运行 windows 7,当我安装 node.js 时,它附带了 NPM 1.4.3。我需要 NPM 2.0.2,所以我 运行 以下内容;
C:\proj>npm install -g npm@2.0.2
npm http GET http://localhost:8000/nexus/content/groups/npm-all/npm/2.0.2
npm http 200 http://localhost:8000/nexus/content/groups/npm-all/npm/2.0.2
npm http GET http://localhost:8000/nexus/content/groups/npm-all/npm/-/npm-2.0.2.tgz
npm http 200 http://localhost:8000/nexus/content/groups/npm-all/npm/-/npm-2.0.2.tgz
C:\Users\pgreen\AppData\Roaming\npm\npm -> C:\Users\pgreen\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm@2.0.2 C:\Users\pgreen\AppData\Roaming\npm\node_modules\npm
输出确实显示我正在使用本地 nexus 插件来执行 NPM 存储库代理,但我没有理由怀疑这会导致任何问题。
安装后我看到:
C:\proj>npm --version
1.4.3
那么我缺少什么才能在命令行上使用 npm 2.0.2 版?
我只需要 RTFM:
Upgrading on Windows
By default, npm is installed alongside node in C:\Program Files (x86)\nodejs. npm's globally installed packages (including, potentially, npm itself) are stored separately in a user-specific directory (which is currently C:\Users\AppData\Roaming\npm). Because the installer puts C:\Program Files (x86)\nodejs before C:\Users\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm@. To get around this, you can do one of the following:
Option 1: edit your Windows installation's PATH to put C:\Users\<username>\AppData\Roaming\npm before C:\Program Files
(x86)\nodejs. Remember that you'll need to restart cmd.exe (and potentially restart Windows) when you make changes to PATH or how npm is installed.
Option 2: remove both of C:\Program Files (x86)\nodejs\npm C:\Program Files (x86)\nodejs\npm.cmd Option 3: navigate to C:\Program Files (x86)\nodejs with cmd.exe and then run the installation without -g:
npm install npm
If you installed npm with the node.js installer, after doing one of the previous steps go into C:\Program Files\nodejs\node_modules\npm and copy the file named npmrc in the new npm folder, which should be C:\Users\AppData\Roaming\npm\node_modules\npm. This will tell the new npm where the global installed packages are. See the point below for more details.
(See also the point below if you're running Windows 7 and don't have the directory C:\Users\AppData\Roaming\npm.)