返回介绍

如何安装 npm 并管理 npm 版本

发布于 2019-05-30 13:06:22 字数 3099 浏览 1127 评论 0 收藏 0

npm is written in Node.js, so you need to install Node.js in order to use npm. You can install npm via the Node.js website, or by installing a Node Version Manager or NVM. This chapter explains both options.

If you just want to get started exploring npm, using the Node.js installation method is fastest. If you are an advanced developer ready to jump in and work with versions, use the node version manager. If you aren't sure, please read this chapter before you decide. You can always change how you run npm in the future.

从 Node.js 网站安装 npm

1. 安装 Node.js 和 npm

If you're using OS X or Windows, use one of the installers from the 2. 更新 npm

When you install node.js, npm is automatically installed. However, npm gets updated more frequently than Node.js, so be sure that you have the latest version.

To test, run npm -v.

To be sure that this matches the latest version, scroll to the bottom of this page. If the version you see does not match the latest version, run:

npm install npm@latest -g.

This will install the latest official, tested version of npm.

To install a version that will be released in the future, run:

npm install npm@next -g.

Using a Version Manager to install Node.js and npm

Since npm and node.js products are managed by different entities, updates and maintenance can become complex. Also, the Node.js installation process installs npm in a directory that only has local permissions. This can cause permissions errors when you attempt to run packages globally.

To solve both these issues, many developers opt to use a node version manager, or nvm, to install npm. The version manager will avoid permissions errors, and will solve the complexities of updating Node.js and npm.

In addition, developers can use an nvm to test their applications on multiple versions of npm. The nvm enables you to easily switch npm as well as node versions. This makes it easier to ensure that your applications work for most users, even if they are using other versions of npm. If you decide to install a version manager, use the instructions for the version manager you select to learn how to switch versions, and to learn how to keep up-to-date with the latest version of npm.

Apple macOS

Click Microsoft Windows

To install and manage npm and Node.js on Windows, we suggest Linux

Click Experimenting with the Next Release

For more advanced users

If you want to try the next, unreleased version of npm to test that packages you have created will work with the planned next release of npm, use this command:

npm install npm@next -g

This may simply reinstall the current version, depending on the development cycle. Also, this early version is not final. So features may or may not match what is ultimately released.

Learn More

To learn more about how to use nvm, click here.

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

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

发布评论

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