更新从注册表下载的本地和全局包有助于保持代码和工具稳定、可用和安全。

¥Updating local and global packages you downloaded from the registry helps keep your code and tools stable, usable, and secure.

更新本地包

¥Updating local packages

我们建议定期更新你的项目所依赖的本地包,以在改进其依赖时改进你的代码。

¥We recommend regularly updating the local packages your project depends on to improve your code as improvements to its dependencies are made.

  1. 导航到项目的根目录并确保它包含 package.json 文件:

    ¥Navigate to the root directory of your project and ensure it contains a package.json file:

    cd /path/to/project
  2. 在你的项目根目录中,运行 update 命令

    ¥In your project root directory, run the update command:

    npm update
  3. 要测试更新,请运行 outdated 命令。这不会有任何输出。

    ¥To test the update, run the outdated command. There should not be any output.

    npm outdated

更新全局安装的包

¥Updating globally-installed packages

注意:如果你使用的是 npm 版本 2.6.0 或更低版本,请运行 此脚本 以更新所有过时的全局包。

¥Note: If you are using npm version 2.6.0 or less, run this script to update all outdated global packages.

但是,请考虑升级到最新版本的 npm:

¥However, please consider upgrading to the latest version of npm:

npm install npm@latest -g

确定哪些全局包需要更新

¥Determining which global packages need updating

要查看需要更新哪些全局包,请在命令行上运行:

¥To see which global packages need to be updated, on the command line, run:

npm outdated -g --depth=0

更新单个全局包

¥Updating a single global package

要更新单个全局包,请在命令行上运行:

¥To update a single global package, on the command line, run:

npm update -g <package_name>

更新所有全局安装的包

¥Updating all globally-installed packages

要更新所有全局包,请在命令行上运行:

¥To update all global packages, on the command line, run:

npm update -g

资源

¥Resources

CLI 命令

¥CLI commands

npm 中文网 - 粤ICP备13048890号