Rust安装——Win10

  • 安装步骤

    • 1、下载RUSTUP-INIT.EXE(64-BIT)

    • 2、由于国外源下载依赖太慢,因此建议增加win10环境变量配置国内源,增加RUSTUP_DIST_SERVER、RUSTUP_UPDATE_ROOT环境变量即可 RUSTUP_DIST_SERVER随便选择其中的一个源就行,只要是国内的,应该都不慢。

      sh 复制代码
      # 字节跳动
      RUSTUP_DIST_SERVER=https://rsproxy.cn
      RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
      
      # 中国科学技术大学
      RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
      RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
      
      # 清华大学
      RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
      
      # 上海交通大学
      RUSTUP_DIST_SERVER=https://mirrors.sjtug.sjtu.edu.cn/rust-static/

      环境变量添加后,查看win10环境变量效果如下:

      sh 复制代码
      C:\Users\david>echo %RUSTUP_DIST_SERVER%
      https://mirrors.tuna.tsinghua.edu.cn/rustup
      
      C:\Users\david>echo %RUSTUP_UPDATE_ROOT%
      https://mirrors.ustc.edu.cn/rust-static/rustup
      
      C:\Users\david>
    • 3、执行RUSTUP-INIT.EXE二进制文件,开始安装Rust

    • 4、按回车选择默认

    • 5、等待脚本自行下载依赖,直到提示安装完成,然后按任意一个按键结束安装

    • 6、验证安装是否成功

      • 6.1、新启动一个命令行终端,输入:rustc -V,查看Rust编译器的版本,如果能看到信息,说明Rust安装没有啥问题

      • 6.2、新建一个文件,命名为main.rs,测试一下Rust的Hello World,文件内容如下

        rust 复制代码
        fn main() {
            println!("Hello World!");
        }
      • 6.2、执行命令:rustc main.rs编译出可执行文件,生成的可执行文件名称为:main.exe

      • 6.3、执行命令:main.exe,若看到程序输出字符:Hello World!,就说明环境搭建的没有问题

    • 7、Cargo是Rust的包管理工具,我们依赖的第三方工具就是通过Cargo完成下载的。但是由于Cargo默认的依赖库下载源在国外,因此需要修改为国内源,步骤如下

      • 7.1、在Cargo的家目录(一般在%USERPROFILE%\.cargo目录下)创建名为config的配置文件

      • 7.2、配置文件内容为:

        ini 复制代码
        [source.crates-io]
        registry = "https://github.com/rust-lang/crates.io-index"
        # 指定镜像 如:tuna、sjtu、ustc,或者 rustcc
        replace-with = 'ustc'
        
        # 注:以下源配置一个即可,无需全部
        
        # 中国科学技术大学
        [source.ustc]
        registry = "https://mirrors.ustc.edu.cn/crates.io-index"
        #registry = "git://mirrors.ustc.edu.cn/crates.io-index"
        
        # 上海交通大学
        [source.sjtu]
        registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index/"
        
        # 清华大学
        [source.tuna]
        registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
        
        # rustcc社区
        [source.rustcc]
        registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
      • 7.3、保存完文件之后,后续不需要关了,cargo会自己更新依赖库

    • 8、安装执行过程如下

      复制代码
      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:
      
        C:\Users\david\.rustup
      
      This can be modified with the RUSTUP_HOME environment variable.
      
      The Cargo home directory is located at:
      
        C:\Users\david\.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:
      
        C:\Users\david\.cargo\bin
      
      This path will then be added to your PATH environment variable by
      modifying the HKEY_CURRENT_USER/Environment/PATH registry key.
      
      You can uninstall at any time with rustup self uninstall and
      these changes will be reverted.
      
      Current installation options:
      
      
         default host triple: x86_64-pc-windows-msvc
           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-pc-windows-msvc
      info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
      710.0 KiB / 710.0 KiB (100 %)  21.9 KiB/s in 41s ETA:  0s
      info: latest update on 2023-12-28, rust version 1.75.0 (82e1608df 2023-12-21)
      info: downloading component 'cargo'
        5.9 MiB /   5.9 MiB (100 %) 204.8 KiB/s in  1m 16s ETA:  0s
      info: downloading component 'clippy'
        2.1 MiB /   2.1 MiB (100 %) 174.6 KiB/s in 13s ETA:  0s
      info: downloading component 'rust-docs'
       14.3 MiB /  14.3 MiB (100 %) 171.8 KiB/s in  1m 19s ETA:  0s
      info: downloading component 'rust-std'
       17.9 MiB /  17.9 MiB (100 %) 120.6 KiB/s in  1m 42s ETA:  0s
      info: downloading component 'rustc'
       58.7 MiB /  58.7 MiB (100 %) 477.4 KiB/s in  6m 36s ETA:  0s
      info: downloading component 'rustfmt'
        1.7 MiB /   1.7 MiB (100 %) 870.3 KiB/s in  2s ETA:  0s
      info: installing component 'cargo'
      info: installing component 'clippy'
      info: installing component 'rust-docs'
       14.3 MiB /  14.3 MiB (100 %)   1.1 MiB/s in  7s ETA:  0s
      info: installing component 'rust-std'
       17.9 MiB /  17.9 MiB (100 %)  14.5 MiB/s in  1s ETA:  0s
      info: installing component 'rustc'
       58.7 MiB /  58.7 MiB (100 %)  15.0 MiB/s in  4s ETA:  0s
      info: installing component 'rustfmt'
      info: default toolchain set to 'stable-x86_64-pc-windows-msvc'
      
        stable-x86_64-pc-windows-msvc installed - rustc 1.75.0 (82e1608df 2023-12-21)
      
      
      Rust is installed now. Great!
      
      To get started you may need to restart your current shell.
      This would reload its PATH environment variable to include
      Cargo's bin directory (%USERPROFILE%\.cargo\bin).
      
      Press the Enter key to continue.
  • 所有安装的文件位置

    • C:\Users\david\.cargo,此目录下安装了Rust相关的很多工具,譬如:cargo, urstc, rustdoc, rust-gdb, rustup等等
    • C:\Users\david\.rustup
  • 卸载Rust

    • 执行命令:rustup self uninstall
  • 更新Rust版本

    • 执行命令:rustup update
相关推荐
武子康17 分钟前
MultiNet6 空闲崩溃:`EXCVADDR=0x8` 后又出现 `CORRUPT HEAP`
人工智能·后端·agent
开开心心_Every31 分钟前
快速隐藏程序工具自定义快捷键一键切换
java·开发语言·前端·spring·智能手机·word·intellij-idea
chenbingjie_c41 分钟前
C++ 多态完全指南:从虚函数重写到虚函数表原理
开发语言·c++
吴卫斌1 小时前
定投ETF实战指南(四):行业/主题ETF——定投的“进攻端“
开发语言·python·股票·量化
武子康2 小时前
MultiNet7 每轮都 clean,ESP32-P4 内存为什么还在掉?
人工智能·后端·agent
超级架构师2 小时前
PRAXO-CORE 2.5.0:用 conformance 和显式边界构建 Go Agent 框架
开发语言·人工智能·后端·golang·ai编程·智能体框架·praxo-core
陈随易2 小时前
AI 运维服务器,安全又可靠的方法
前端·后端·程序员
叼烟扛炮3 小时前
Linux 学习笔记(四十三):网络编程进阶——自定义协议解决 TCP 粘包与守护进程
linux·开发语言·网络·笔记·tcp/ip
LMT流氓兔3 小时前
第五单元——第十六课:给书店助手加上网页界面
java·开发语言·jvm·人工智能·oracle·langchain·1024程序员节
专注仿真3 小时前
梯度提升类(XFBoost)算法详解与代码实例
开发语言·人工智能·python·算法·大模型训练·控制算法