返回介绍

Try the latest stable version of npm

发布于 2019-05-30 13:06:42 字数 3649 浏览 1096 评论 0 收藏 0

See what version of npm you're running:

npm -v

Upgrading on *nix (OSX, Linux, etc.)

(You may need to prefix these commands with sudo, especially on Linux, or OS X if you installed Node using its default installer.)

You can upgrade to the latest version of npm using:

npm install -g npm@latest

Or upgrade to the most recent release:

npm install -g npm@next

Upgrading on Windows

Microsoft wrote a small command line tool to automate the steps below. to put %appdata%\npm before %ProgramFiles%\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

    • %ProgramFiles%\nodejs\npm
    • %ProgramFiles%\nodejs\npm.cmd
  • Option 3: Navigate to %ProgramFiles%\nodejs\node_modules\npm and copy the npmrcfile to another folder or the desktop. Then open cmd.exe and run the following commands:

  • cd %ProgramFiles%\nodejs
    npm install npm@latest

    If you installed npm with the node.js installer, after doing one of the previous steps, do the following.

    • Option 1 or 2

      • Go into %ProgramFiles%\nodejs\node_modules\npm and copy the file named npmrc in the new npm folder, which should be %appdata%\npm\node_modules\npm. This will tell the new npm where the global installed packages are.
    • Option 3

      • Copy the npmrc file back into %ProgramFiles%\nodejs\node_modules\npm

    (See also the A brief note on the built-in Windows configuration

    The Node installer installs, directly into the npm folder, a special piece of Windows-specific configuration that tells npm where to install global packages. When npm is used to install itself, it is supposed to copy this special builtin configuration into the new install. There was a bug in some versions of npm that kept this from working, so you may need to go in and fix that up by hand. Run the following command to see where npm will install global packages to verify it is correct.

    npm config get prefix -g
    

    If it isn't set to <X>:\Users\<user>\AppData\Roaming\npm, you can run the below command to correct it:

    npm config set prefix "${APPDATA}/npm" -g
    

    Incidentally, if you would prefer that packages not be installed to your roaming profile (because you have a quota on your shared network, or it makes logging in or out from a domain sluggish), you can put it in your local app data instead:

    npm config set prefix "${LOCALAPPDATA}/npm" -g
    

    ...as well as copying %APPDATA%\npm to %LOCALAPPDATA%\npm (and updating your %PATH%, of course).

    Everyone who works on npm knows that this process is complicated and fraught, and we're working on making it simpler. Stay tuned.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
    列表为空,暂无数据
      我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
      原文