安装Rust(Windows 10 与 CentOS7)

注:安装及下载需要科学上网 

官网下载地址:Install Rust - Rust Programming Language

Window安装Rust 

0、前提条件

安装C++编译工具(如下图所示)

1、下载安装程序

2、设置环境变量(可略过)

可以通过设置环境变量,将rust安装到自己设置的目录中,不设置安装到默认的路径C:\Users\用户名\.rust中。

2.1、搜索“环境变量”

2.2、打开系统属性 > 高级 > 环境变量

2.3、用户变量或系统变量 > 新建

2.4、添加环境变量

  • RUSTUP_HOME
  • CARGO_HOME

3、安装rust

3.1、双击下载的rustup-init.exe文件

 

3.2、输入2

 

3.3、根据提示进行输入或回车(默认)

第1步中输入:x86_64-pc-windows-gnu   后面直接回车即可,最后安装输入1

3.4、等待安装完成

4、验证

打开命令提示符窗囗,输入如下命令进行验证:

rustc --version 

CentOS7 安装 Rust

1、安装Rust

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

安装过程中,需要选择1,2,3,输入1进行默认安装即可,如下所示:

[root@localhost ~]# 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
>1

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'
info: latest update on 2022-09-22, rust version 1.64.0 (a55dd71d5 2022-09-19)
info: downloading component 'cargo'
  6.4 MiB /   6.4 MiB (100 %) 979.2 KiB/s in  6s ETA:  0s
info: downloading component 'clippy'
  2.8 MiB /   2.8 MiB (100 %) 1023.7 KiB/s in  3s ETA:  0s
info: downloading component 'rust-docs'
 18.8 MiB /  18.8 MiB (100 %) 985.6 KiB/s in 20s ETA:  0s 
info: downloading component 'rust-std'
 27.4 MiB /  27.4 MiB (100 %) 924.8 KiB/s in 29s ETA:  0s 
info: downloading component 'rustc'
 18.7 MiB /  54.2 MiB ( 34 %) 812.8 KiB/s in  1m  4s ETA: 44s
info: retrying download for 'https://static.rust-lang.org/dist/2022-09-22/rustc-1.64.0-x86_64-unknown-linux-gnu.tar.xz'
 54.2 MiB /  54.2 MiB (100 %) 940.8 KiB/s in 58s ETA:  0s 
info: downloading component 'rustfmt'
  4.3 MiB /   4.3 MiB (100 %) 955.9 KiB/s in  4s ETA:  0s
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.8 MiB /  18.8 MiB (100 %)   2.8 MiB/s in  6s ETA:  0s
info: installing component 'rust-std'
 27.4 MiB /  27.4 MiB (100 %)  13.2 MiB/s in  2s ETA:  0s
info: installing component 'rustc'
 54.2 MiB /  54.2 MiB (100 %)  15.2 MiB/s in  3s 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.64.0 (a55dd71d5 2022-09-19)


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"

2、使环境生效

source $HOME/.cargo/env

[root@localhost ~]# rustc -V
bash: rustc: command not found...              #环境未生效
[root@localhost ~]# source $HOME/.cargo/env    #使环境生效
[root@localhost ~]# rustc -V
rustc 1.64.0 (a55dd71d5 2022-09-19)            #环境已生效,得到版本信息
[root@localhost ~]# cargo --version
cargo 1.64.0 (387270bc7 2022-09-16)

猜你喜欢

转载自blog.csdn.net/ling1998/article/details/127216357