【问题标题】:Is there a command to update Cargo to the latest official release?是否有命令将 Cargo 更新到最新的官方版本?
【发布时间】:2016-10-22 01:37:02
【问题描述】:

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

$ 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

【问题讨论】:

标签: rust package-managers rust-cargo


【解决方案1】:

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

rustccargo 一起发布,但这并不意味着它们的版本需要匹配。事实上,直到 Rust 1.26.0,它们匹配,当时the Cargo binary was changed to print the Rust version

我有和你一样的rustccargo 版本;这些是对应于 Rust 1.9 版本的那些。没什么好担心的。


如果你真的想要,你可以download a nightly version of Cargocompile your own。只要您的版本存在于您的PATH 之前的旧版本中,就会被使用。

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

【讨论】:

    【解决方案2】:

    TL;DR 版本:rustup 将同时更新 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)
    

    【讨论】:

      【解决方案3】:

      您还需要更改默认值:

      > 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)
      

      【讨论】:

        【解决方案4】:

        使用 cargo 更新自身:

        cargo install cargo --force
        

        这会重新编译包并安装最新版本。

        在看到 rustup 没有将 cargo 更新到 1.57 后,我决定发布此内容

        【讨论】: