关于rust:是否有命令将Cargo更新到最新的正式版本?

Is there a command to update Cargo to the latest official release?

我似乎对rustccargo有不同的版本(我认为),

1
2
3
4
$ rustc -V
rustc 1.9.0 (e4e8b6668 2016-05-18)
$ cargo -V
cargo 0.10.0-nightly (10ddd7d 2016-04-08)

是否存在类似于

的命令

1
pip install --upgrade pip

用于升级cargo? IE。类似

1
cargo install --upgrade cargo


您应根据安装方式来更新rustccargo。如果您使用rustup,则rustup update就足够了。如果您使用了程序包管理器或二进制安装程序,请检查这些源以获取更新。

rustccargo一起提供,但这并不意味着它们的版本需要匹配。实际上,直到Rust 1.26.0(将Cargo二进制文件更改为打印Rust版本)后,它们才匹配。

我拥有与rustccargo相同的版本;这些是与Rust 1.9发行版相对应的。不用担心。

如果您确实愿意,可以下载每晚版本的Cargo或自己编译。只要您的版本在较早版本的PATH中存在,就会使用该版本。

我曾经使用我的本地Rust构建来完成此操作,以便完全拥有Cargo版本,尽管当当前工具链中没有可用的版本时,rustup现在会自动使用最新稳定版本中的cargo ,这很好。


TL; DR版本:rustup将同时更新Rust和Cargo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ rustc --version
rustc 1.27.2 (58cc626de 2018-07-18)
$ cargo --version
cargo 1.27.0 (1e95190e5 2018-05-27)

$ rustup update stable
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2018-08-02, rust version 1.28.0 (9634041f0 2018-07-30)
info: downloading component 'rustc'
info: downloading component 'rust-std'
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: removing component 'rustc'
info: removing component 'rust-std'
info: removing component 'cargo'
info: removing component 'rust-docs'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'

$ rustc --version
rustc 1.28.0 (9634041f0 2018-07-30)
$ cargo --version
cargo 1.28.0 (96a2c7d16 2018-07-13)

您还需要更改默认值:

1
2
3
4
5
6
7
8
9
10
11
12
> rustc --version
rustc 1.41.0 (5e1a79984 2020-01-27)

> rustup update stable

> rustc --version
rustc 1.41.0 (5e1a79984 2020-01-27)

> rustup default stable-x86_64-apple-darwin

> rustc --version
rustc 1.47.0 (18bf6b4f0 2020-10-07)