rustup 使用


rustup 可以幫助我們安裝不同版本的rust 編程需要的工具連,同時可以方便的進行不同版本
之間的切換,類似nodejs 的nvm,n, ruby 的 rvm python 的 venv 。。。

rustup 基本使用

我們在首次使用安裝腳本,或者安裝包安裝完成rust 之后就會附帶rustup了,對於需要使用不同版本
的流程如下:

  • 選擇一個版本,rust 提供了不同的channnel(nightly,stabel,beta. date 格式..)
  • 使用rustup install 指定版本,或者rustup toolchain install
  • 指定rustup default version 進行版本切換
  • 使用rustup toolchain list 或者rustup show檢查切換配置

rustup 幫助

  • toolchain
rustup-toolchain 
Modify or query the installed toolchains
USAGE:
    rustup toolchain <SUBCOMMAND>
FLAGS:
    -h, --help Prints help information
SUBCOMMANDS:
    list List installed toolchains
    install Install or update a given toolchain
    uninstall Uninstall a toolchain
    link Create a custom toolchain by symlinking to a directory
    help Prints this message or the help of the given subcommand(s)
DISCUSSION:
    Many `rustup` commands deal with *toolchains*, a single
    installation of the Rust compiler. `rustup` supports multiple
    types of toolchains. The most basic track the official release
    channels: 'stable', 'beta' and 'nightly'; but `rustup` can also
    install toolchains from the official archives, for alternate host
    platforms, and from local builds.
    Standard release channel toolchain names have the following form:
        <channel>[-<date>][-<host>]
        <channel> = stable|beta|nightly|<version>
        <date> = YYYY-MM-DD
        <host> = <target-triple>
    'channel' is either a named release channel or an explicit version
    number, such as '1.8.0'. Channel names can be optionally appended
    with an archive date, as in 'nightly-2017-05-09', in which case
    the toolchain is downloaded from the archive for that date.
    Finally, the host may be specified as a target triple. This is
    most useful for installing a 32-bit compiler on a 64-bit platform,
    or for installing the [MSVC-based toolchain] on Windows. For
    example:
        $ rustup toolchain install stable-x86_64-pc-windows-msvc
    For convenience, elements of the target triple that are omitted
    will be inferred, so the above could be written:
        $ rustup default stable-msvc
    rustup can also manage symlinked local toolchain builds, which are
    often used to for developing Rust itself. For more information see
    `rustup toolchain help link`.

一個簡單安裝例子

比如我們需要安裝一個nightly-2019-01-17 , 這個格式遵循上邊的約定

  • 安裝如下:
rustup toolchain install nightly-2019-01-17

信息如下:

可以看出信息還是很詳細的(我們同時也知道了版本)

rustup toolchain install nightly-2019-01-17
info: syncing channel updates for 'nightly-2019-01-17-x86_64-apple-darwin'
316.6 KiB / 316.6 KiB (100 %) 223.0 KiB/s in 1s ETA: 0s
info: latest update on 2019-01-17, rust version 1.33.0-nightly (ceb251214 2019-01-16)
info: downloading component 'rustc'
 78.6 MiB / 78.6 MiB (100 %) 537.6 KiB/s in 3m 6s ETA: 0s 
info: downloading component 'rust-std'
 48.0 MiB / 51.3 MiB ( 94 %) 44.8 KiB/s in 3m 14s ETA: 1m 15s
 48.0 MiB / 51.3 MiB ( 94 %) 48.0 KiB/s in 3m 16s ETA: 1m 8s
 51.3 MiB / 51.3 MiB (100 %) 282.4 KiB/s in 3m 36s ETA: 0s 
info: downloading component 'cargo'
  3.4 MiB / 3.4 MiB (100 %) 388.1 KiB/s in 9s ETA: 0s 
info: downloading component 'rust-docs'
  8.5 MiB / 8.5 MiB (100 %) 606.9 KiB/s in 18s ETA: 0s
info: installing component 'rustc'
 78.6 MiB / 78.6 MiB (100 %) 8.9 MiB/s in 7s ETA: 0s
info: installing component 'rust-std'
 51.3 MiB / 51.3 MiB (100 %) 12.1 MiB/s in 4s ETA: 0s
info: installing component 'cargo'
info: installing component 'rust-docs'
  8.5 MiB / 8.5 MiB (100 %) 1.3 MiB/s in 6s ETA: 0s
  nightly-2019-01-17-x86_64-apple-darwin installed - rustc 1.33.0-nightly (ceb251214 2019-01-16)
info: checking for self-updates
 
  • 啟動新的為default
rustup default nightly-2019-01-17
  • 查看toolchain
rustup toolchain list 

效果:

stable-x86_64-apple-darwin
nightly-2019-01-17-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin
 
  • 配置default

    我們可以使用 <channel>[-<date>][-<host>] 格式,也可以使用 toolchain list 看到的版本

rustup default nightly-2019-01-17

效果

info: using existing install for 'nightly-2019-01-17-x86_64-apple-darwin'
info: default toolchain set to 'nightly-2019-01-17-x86_64-apple-darwin'
  nightly-2019-01-17-x86_64-apple-darwin unchanged - rustc 1.33.0-nightly (ceb251214 2019-01-16)
  • 檢查default
rustup show

效果:

Default host: x86_64-apple-darwin
installed toolchains
--------------------
stable-x86_64-apple-darwin
nightly-2019-01-17-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin
active toolchain
----------------
nightly-2019-01-17-x86_64-apple-darwin (default)
rustc 1.33.0-nightly (ceb251214 2019-01-16)
 
 

或者:

rustup toolchain list

效果:

stable-x86_64-apple-darwin
nightly-2019-01-17-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin

說明

因為rust 語言的變動,可能經常碰到編譯問題(依賴別人的包),通過rustup 的版本管理,基本上可以解決我們
實際碰到的問題,同時對於不同版本包的問題,可以結合github 的issue 進行查看(好多時候都會找到的)

參考資料

https://forge.rust-lang.org/channel-layout.html
https://forge.rust-lang.org/
https://forge.rust-lang.org/releases.html
https://rust-lang.github.io/rustup-components-history/index.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM