cargo-update(1)

NAME

cargo-update - Update dependencies as recorded in the local lock file

SYNOPSIS

cargo update [options]

DESCRIPTION

This command will update dependencies in the Cargo.lock file to the latest version. If the Cargo.lock file does not exist, it will be created with the latest available versions.

OPTIONS

Update Options

-p spec...
--package spec...
Update only the specified packages. This flag may be specified multiple times. See cargo-pkgid(1) for the SPEC format.

If packages are specified with the -p flag, then a conservative update of the lockfile will be performed. This means that only the dependency specified by SPEC will be updated. Its transitive dependencies will be updated only if SPEC cannot be updated without updating dependencies. All other dependencies will remain locked at their currently recorded versions.

If -p is not specified, all dependencies are updated.

--aggressive
When used with -p, dependencies of spec are forced to update as well. Cannot be used with --precise.
--precise precise
When used with -p, allows you to specify a specific version number to set the package to. If the package comes from a git repository, this can be a git revision (such as a SHA hash or tag).
-w
--workspace
Attempt to update only packages defined in the workspace. Other packages are updated only if they don't already exist in the lockfile. This option is useful for updating Cargo.lock after you've changed version numbers in Cargo.toml.
--dry-run
Displays what would be updated, but doesn't actually write the lockfile.

Display Options

-v
--verbose
启用更加详细的输出。可两次使用来显示"非常详细"的输出,其中包含了诸如 依赖警告 以及 构建脚本输出 等额外的输出内容。 也可通过term.verbose指定。 config value.
-q
--quiet
不输出Cargo的日志信息。也可通过term.quiet指定。 config value.
--color when
控制输出内容的颜色。有效取值如下:

  • auto (默认):自动检测终端是否支持带颜色的输出。
  • always:总显示带颜色的输出。
  • never:从不显示带颜色的输出。

也可通过term.color指定。 config value.

Manifest Options

--manifest-path path
用于指定Cargo.toml文件的路径。默认情况下,Cargo会在当前目录或上级目录中寻找Cargo.toml文件。
--frozen
--locked
这两个选项用于保证Cargo.lock文件是最新的。如果该锁文件不存在,或者不是最新的,Cargo 会报错退出。其中--frozen选项会阻止Cargo访问网络以检查锁文件是否是最新的。

这些选项,可用于保证Cargo.lock文件是最新的(比如持续集成的构建过程), 或用于避免联网。

--offline
禁止Cargo访问网络。如果不添加此选项,Cargo在需要访问网络但网络不可用的情况下,会报错 并停止工作。添加此选项后,Cargo会尽可能尝试不使用网络来工作。

注意,在此情况下可能会产生与联网状态下不同的依赖解析(Dependency Resolution)结果。 Cargo只会使用本地已下载的crate,即便本地的索引副本中表明可能有新版本crate。在离线前下载 所需依赖的方法,参见 cargo-fetch(1)

也可以通过 net.offline config value指定。

Common Options

+toolchain
If Cargo has been installed with rustup, and the first argument to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +nightly). See the rustup documentation for more information about how toolchain overrides work.
-h
--help
Prints help information.
-Z flag
Unstable (nightly-only) flags to Cargo. Run cargo -Z help for details.

环境

关于Cargo所读取的环境变量,可参见the reference

退出状态

  • 0: Cargo命令执行成功
  • 101: Cargo命令未能完成.

EXAMPLES

  1. Update all dependencies in the lockfile:

    cargo update
    
  2. Update only specific dependencies:

    cargo update -p foo -p bar
    
  3. Set a specific dependency to a specific version:

    cargo update -p foo --precise 1.2.3
    

SEE ALSO

cargo(1), cargo-generate-lockfile(1)