rust部署

启用 TUNA 源

临时启用 TUNA 源

# export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup

长期启用 TUNA 源

# echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup' >> ~/.bash_profile
# echo 'export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup' >> ~/.bash_profile

安装rust

查看代码
 # curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /root/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /root/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /root/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /root/.profile
  /root/.bash_profile
  /root/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
warning: Signature verification failed for 'https://mirrors.tuna.tsinghua.edu.cn/rustup/dist/channel-rust-stable.toml'
info: latest update on 2022-08-11, rust version 1.63.0 (4b91a6ea7 2022-08-08)
info: downloading component 'cargo'
  6.6 MiB /   6.6 MiB (100 %)   3.5 MiB/s in  2s ETA:  0s
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %)   3.6 MiB/s in  5s ETA:  0s
info: downloading component 'rust-std'
 26.1 MiB /  26.1 MiB (100 %)   3.8 MiB/s in  7s ETA:  0s
info: downloading component 'rustc'
 54.3 MiB /  54.3 MiB (100 %)   3.1 MiB/s in 15s ETA:  0s
info: downloading component 'rustfmt'
  4.1 MiB /   4.1 MiB (100 %)   3.7 MiB/s in  1s ETA:  0s
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %)   5.6 MiB/s in  2s ETA:  0s
info: installing component 'rust-std'
 26.1 MiB /  26.1 MiB (100 %)   8.8 MiB/s in  4s ETA:  0s
info: installing component 'rustc'
 54.3 MiB /  54.3 MiB (100 %)  10.0 MiB/s in  5s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.63.0 (4b91a6ea7 2022-08-08)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"

配置PATH环境变量

# source "$HOME/.cargo/env"

rust常用命令

rustup update   # 版本更新

rustc --version  # 查看版本信息

rustup target list   # 查看target列表

rustup target add xxx  # 添加工具链,xxx为rustup target list 的结果, eg:rustup target add armv7-unknown-linux-gnueabihf

rustup default  xxx      # 切换版本,xxx为版本号    eg:rustup default 1.46.0

卸载rust

# rustup self uninstall

cargo更换国内源

cat .cargo/config

[source.crates-io]

replace-with = 'tuna'    # 替换成你偏好的镜像源

[source.tuna]  # 清华大学
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

参考文档

https://mirrors.tuna.tsinghua.edu.cn/help/rustup/

https://www.rust-lang.org/tools/install

posted @ 2022-08-23 14:44  小吉猫  阅读(256)  评论(0编辑  收藏  举报