Rust install, uninstall, nightly/stable version switch (global or workspace)

Rust installation, update and version control

Copyright, no reprint without permission
Time: time
created by: Tower

1.1 installation

1.1.1 download the installer of rule
Rust recommends using the rustup program to manage the basic tools such as the rust compiler, which can be found on the official website Rustup installation package address

rustup is a tool for installing and managing the build of Rust. rustup is used to manage and make the build versions of Rust compatible with each other under different platforms. It supports the installation of versions released by Beta and Nightly channels, and supports other build versions used for cross compilation
cargo is the package manager and build system tool of rust. It integrates common commands without introducing other commands.

Rustup program is the installation program and version management program of rust. It is similar to the conda tool of Anaconda distribution of Python, which is very convenient to use and manage. Cargo is the construction tool of rust, which will not be introduced for the moment. It needs to be understood that: rustup is the management language itself, and cargo is the management of third-party expansion.

1.1.2 configuration and installation of operation installer
Take the stable version as an example


Ok, this is a successful installation. This is the simplicity of using the installer. Of course, we need to check whether the installation is successful

Test whether the installation is successful
Run command line: win+R, enter cmd
input

rustc --version
//Or rustc-v


If the version number appears as shown in the figure, the installation is successful. If there is a problem, the environment variable needs to be detected, as follows:

Configure PATH environment variable
In the rule development environment, all tools are installed in the ~ /. cargo/bin directory, where you can find the rule tool chain including rustc, cargo and rustup.

The most common way for a rule developer is to add this directory to the PATH environment variable. During installation, rustup attempts to configure PATH. Due to the differences between different platforms and command-line shells, there may be bugs in rustup. Therefore, before the terminal restarts or the user logs in again, the PATH modification of rustup may not take effect or even be completely invalid.

The above is the most likely cause if an attempt to execute the rustc --version fails on the terminal after installation.

Install the specified version
Run command line: win+R, enter cmd
input

rustup install version number

1.2 uninstall

Because of the installer, uninstalling the rule environment is simple:
Run command line: win+R, enter cmd
input

rustup self uninstall

1.3 update

Run command line: win+R, enter cmd
input

# Update to the latest version
rustup update
# Update to specified version number
rustup update _version_number_xxx

The command without specifying the version number will update all versions (stable, nightly, beta) of toolchain. If only one of them is installed, only one will be updated. The following figure shows the situation with nightly and stable environments

1.4 switch of mirror source of rule

When studying Rust, due to well-known reasons, it was found that the code of pulling crates.io warehouse was too slow, and the slow download and update of cargo installation was intolerable. Many times of timeout resulted in the failure of compilation of reference library, so the update and download source of reference library was replaced. Here, you can switch to the domestic image (image source of University of science and technology of China). The configuration is as follows:

Find the. cargo folder of. cargo / under the current user directory, enter the current directory of. cargo, and create the config file under the current directory

Open the config file and write the following:

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

If git protocol is allowed in your environment, you can change the above address to:
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

You can search other image sources by yourself

1.5 rule nightly / beta / stable version switch

1.5.1 view installed version

Run command line: win+R, enter cmd
input

rustup toolchain list


Or, go to $Home/.rustup/toolchain to see the installed version

1.5.2 switch to a specific version

Run command line: win+R, enter cmd
input

rustup default stable/nightly/beta

Switch global rule environment: defalut

rustup default version
Change to nightly if version is nightly
If version specifies stable, switch to stable

If nightly or stable is installed in the computer, the corresponding version will be automatically downloaded by executing the command

Switch the rule environment of working directory: override
Open the command line in the corresponding working directory, and enter the command as follows:
rustup override set version
version:stable/nightly/beta

PS D:\workspace\rustwp> rustc -V
rustc 1.40.0 (73528e339 2019-12-16)
PS D:\workspace\rustwp> rustup override set nightly
info: using existing install for 'nightly-x86_64-pc-windows-msvc'
info: override toolchain for 'D:\workspace\rustwp' set to 'nightly-x86_64-pc-windows-msvc'

  nightly-x86_64-pc-windows-msvc unchanged - rustc 1.42.0-nightly (6d3f4e0aa 2020-01-25)

PS D:\workspace\rustwp> rustc -V
rustc 1.42.0-nightly (6d3f4e0aa 2020-01-25)
PS D:\workspace\rustwp>

Switch the t rust environment of the working directory to the global default environment:
rustup override unset

PS D:\workspace\rustwp> rustup override unset 
info: override toolchain for 'D:\workspace\rustwp' removed

Welcome to technology Renaissance

Introduction to toolchain
It is necessary to understand the meaning of toolchain in rust: recognize it as a version, easy to manage

You can enter rustup help toolchain on the command line to see and understand what toolchain is and how to use it

C:\Users\18755>rustup help 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.

    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, omitted elements of the target triple will be
    inferred, so the above could be written:

        $ rustup toolchain install stable-msvc

    The `rustup default` command may be used to both install and set
    the desired toolchain as default in a single command:

        $ rustup default stable-msvc

    rustup can also manage symlinked local toolchain builds, which are
    often used for developing Rust itself. For more information see
    `rustup toolchain help link`.

Introduction to override

PS D:\workspace\rustwp> rustup help override
rustup.exe-override 
Modify directory toolchain overrides

USAGE:
    rustup.exe override <SUBCOMMAND>

FLAGS:
    -h, --help    Prints help information

SUBCOMMANDS:
    list     List directory toolchain overrides
    set      Set the override toolchain for a directory
    unset    Remove the override toolchain for a directory
    help     Prints this message or the help of the given subcommand(s)

DISCUSSION:
    Overrides configure rustup to use a specific toolchain when
    running in a specific directory.

    Directories can be assigned their own Rust toolchain with `rustup
    override`. When a directory has an override then any time `rustc`
    or `cargo` is run inside that directory, or one of its child
    directories, the override toolchain will be invoked.

    To pin to a specific nightly:

        $ rustup override set nightly-2014-12-18

    Or a specific stable release:

        $ rustup override set 1.0.0

    To see the active toolchain use `rustup show`. To remove the
    override and use the default toolchain again, `rustup override
    unset`.
Published 21 original articles, won praise 22, visited 10000+
Private letter follow

Tags: Windows git Anaconda Python

Posted on Sun, 26 Jan 2020 07:14:37 -0500 by ckjian