Rust Tools

Sources:

  1. --> How To Install Rust on Ubuntu 20.04

Install

  1. Run the command to download the rustup tool and install the latest stable version of Rust:

    1
    curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh

    Next, run the following command to add the Rust toolchain directory to the PATH environment variable:

    1
    source $HOME/.cargo/env
  2. Verify the Rust installation by requesting the version:

    1
    rustc --version
  3. Installing a Compiler

    Rust requires a linker program to join compiled outputs into one file. The GNU Compiler Collection (gcc) in the build-essential package includes a linker. If you don’t install gcc, you need to use apt to install the build-essential package.

    1. First, update the Apt package index:

      1
      sudo apt update
    2. Next, upgrade any out-of-date packages:

      1
      sudo apt upgrade
    3. When the upgrades are complete, install the build-essential package:

      1
      sudo apt install build-essential

Now rust and corresponding tools (rustup, cargo) have been installed

Update

1
2
rustup update stable
rustup default stable

Switch source

If you're in China, you need to download from a mirror site instead of the original site.

There're various mirrors like USTC mirror, tuna mirror, etc. Remember to compare their speed before choosing. Sometimes ustc mirror can be very slow and sometimes tuna mirrir can be very slow.

1
2
mkdir -p ~/.cargo
vim ~/.cargo/config.toml

Write:

1
2
3
4
5
[source.crates-io]
replace-with = "tuna"

[source.tuna]
registry = "sparse+https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/"

Also, edit your ~/.bashrc or ~/.zshrc:

1
2
3
# Add following:
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
export RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup