我似乎有不同版本的
rustc
和cargo
(我认为),
$ rustc -V
rustc 1.9.0 (e4e8b6668 2016-05-18)
$ cargo -V
cargo 0.10.0-nightly (10ddd7d 2016-04-08)
是否有类似于
的命令pip install --upgrade pip
升级
cargo
? IE。像这样的东西
cargo install --upgrade cargo
您应该根据安装方式更新
rustc
和cargo
。如果您使用 rustup,一个rustup update
就足够了。如果您使用包管理器或二进制安装程序,请检查这些源以获取更新。
rustc
和 cargo
一起发货,但这并不意味着它们的版本需要匹配。事实上,它们直到 Rust 1.26.0 才 匹配,当时Cargo 二进制文件被更改为打印 Rust 版本。
我有和你一样的
rustc
和cargo
版本;这些是与 Rust 1.9 版本相对应的那些。没有什么可担心的。
如果你真的想要,你可以下载夜间版本的 Cargo 或 编译你自己的。只要你的版本存在于旧版本之前的
PATH
,它就会被使用。
我曾经在本地 Rust 构建中这样做,以便完全拥有一个 Cargo 版本,尽管 rustup 现在在当前工具链中没有可用版本时自动使用最新稳定版本中的
cargo
,这很好。
tl;dr 命令
rustup update
将同时更新 Rust 和 Cargo:
$ 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)
您还需要更改默认值:
> 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)
使用 cargo 自我更新:
cargo install cargo --force
这将重新编译软件包并安装最新版本。
看到 rustup 没有将 cargo 更新到 1.57 后,我决定发布这个
您可以使用 rustup cli 编辑您正在使用的 cargo 和 rust 的版本。你可以给它一个特定的版本或指定一个频道,比如每晚或测试版。
例如:
rustup override set nightly