安装Rust

news2024/10/1 12:10:26

Rust 是一种系统级编程语言,旨在提供高性能和内存安全,同时避免常见的编程错误。
由 Mozilla Research 推出,Rust 自推出以来因其独特的设计理念和强大的功能而在开发者社区中迅速获得了广泛的关注和采用。

curl --proto ‘=https’ --tlsv1.2 -sSf https://sh.rustup.rs | sh info: downloading installer

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:

/home/jjmczd/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

/home/jjmczd/.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:

/home/jjmczd/.cargo/bin

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

/home/jjmczd/.profile /home/jjmczd/.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 standard installation (default - just press enter) 2)
    Customize installation 3) Cancel installation

命令解释

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

分解说明:

  1. curl:这是一个用于在命令行下传输数据的工具,支持多种协议(如 HTTP、HTTPS、FTP 等)。

  2. --proto '=https':指定只允许使用 HTTPS 协议进行传输,确保数据传输的安全性。

  3. --tlsv1.2:强制 curl 使用 TLS 1.2 协议,这是一种安全的传输层协议。

  4. -s:静默模式(silent),在执行过程中不会显示进度条或错误信息。

  5. -Sf

    • -S:当使用 -s(静默模式)时,-S 可以让 curl 在发生错误时仍然显示错误信息。
    • -f:如果服务器返回一个错误状态码(如 404),curl 会失败并返回一个错误,而不是输出错误页面的内容。
  6. https://sh.rustup.rs:这是 Rust 官方提供的安装脚本的 URL。

  7. | sh:管道符号(|)将前一个命令(curl)的输出传递给后一个命令(sh)。也就是说,下载的安装脚本将直接由 sh(shell)执行。

整体作用:
这个命令通过安全的 HTTPS 连接下载 Rust 的安装脚本,并立即在您的终端中执行该脚本,以便安装 Rust 编程语言及其工具链。

输出解释

info: downloading installer

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:

  /home/jjmczd/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/jjmczd/.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:

  /home/jjmczd/.cargo/bin

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

  /home/jjmczd/.profile
  /home/jjmczd/.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 standard installation (default - just press enter)
2) Customize installation
3) Cancel installation

逐行解释:

  1. info: downloading installer

    • 解释:安装程序正在下载过程中。
  2. Welcome to Rust!

    • 解释:欢迎使用 Rust!
  3. 接下来的几行

    • 解释:这些行说明了安装过程将会下载和安装 Rust 官方编译器(rustc)以及其包管理器(Cargo)。
  4. Rustup metadata and toolchains will be installed into the Rustup home directory, located at:

    • 解释:Rustup 的元数据和工具链将被安装到指定的 Rustup 主目录中,默认路径为 /home/jjmczd/.rustup。您可以通过设置 RUSTUP_HOME 环境变量来修改此路径。
  5. The Cargo home directory is located at:

    • 解释:Cargo 的主目录位于 /home/jjmczd/.cargo。同样,您可以通过设置 CARGO_HOME 环境变量来修改此路径。
  6. The cargo, rustc, rustup and other commands will be added to Cargo's bin directory, located at:

    • 解释cargorustcrustup 以及其他相关命令将被添加到 Cargo 的 bin 目录中,即 /home/jjmczd/.cargo/bin
  7. This path will then be added to your PATH environment variable by modifying the profile files located at:

    • 解释:安装程序会将上述 bin 目录路径添加到您的 PATH 环境变量中,这通过修改您的 shell 配置文件(如 /home/jjmczd/.profile/home/jjmczd/.bashrc)来实现。这样,您可以在任何终端会话中直接运行 Rust 的命令。
  8. You can uninstall at any time with rustup self uninstall and these changes will be reverted.

    • 解释:如果您在任何时候想要卸载 Rust,可以运行 rustup self uninstall 命令,这将撤销所有安装的更改。
  9. Current installation options:

    • 解释:当前的安装选项如下:

    • default host triple: x86_64-unknown-linux-gnu

      • 解释:默认的主机三元组(host triple)是 x86_64-unknown-linux-gnu,表示安装的是适用于 64 位 Linux 系统的 Rust 工具链。
    • default toolchain: stable (default)

      • 解释:默认的工具链是 stable 版本,这是 Rust 的稳定版本,适合大多数用户和生产环境使用。
    • profile: default

      • 解释:使用的是默认的安装配置文件,包含基本的组件和设置。
    • modify PATH variable: yes

      • 解释:安装程序将修改您的 PATH 环境变量,以便您可以在终端中直接使用 Rust 的命令。
  10. 安装选项菜单:

    1) Proceed with standard installation (default - just press enter)
    2) Customize installation
    3) Cancel installation
    
    • 1) Proceed with standard installation (default - just press enter)

      • 解释:继续标准安装(默认选项)。如果您按回车键,将使用上述默认设置进行安装。
    • 2) Customize installation

      • 解释:自定义安装。选择此选项可以让您自定义安装路径、选择不同的工具链版本或调整其他安装选项。
    • 3) Cancel installation

      • 解释:取消安装。选择此选项将终止 Rust 的安装过程。

接下来的步骤

  1. 选择安装选项:

    • 标准安装:如果您不需要自定义安装,直接按回车键继续。这将使用默认设置进行安装。
    • 自定义安装:如果您需要更改安装路径或选择特定的工具链版本,可以输入 2 并按照提示进行操作。
    • 取消安装:如果您暂时不想安装 Rust,可以输入 3 取消。
  2. 完成安装:

    • 安装完成后,确保重新启动终端或重新加载 shell 配置文件,以便新的 PATH 设置生效。

    • 您可以通过运行以下命令来验证 Rust 是否安装成功:

      rustc --version
      cargo --version
      

      这两个命令应分别返回 Rust 编译器和 Cargo 的版本信息。

  3. 更新 Rust(可选):

    • 如果您已经安装过 Rust,可以通过以下命令更新到最新版本:

      rustup update
      

常见问题

  • PATH 环境变量未更新:
    如果安装后运行 rustc --version 提示找不到命令,可能是因为 PATH 环境变量未正确更新。您可以手动添加 Cargo 的 bin 目录到 PATH 中,例如:

    export PATH="$HOME/.cargo/bin:$PATH"
    

    将上述行添加到您的 ~/.bashrc~/.profile 文件中,然后重新加载配置:

    source ~/.bashrc
    
  • 卸载 Rust:
    如果需要卸载 Rust,可以运行以下命令:

    rustup self uninstall
    

    这将删除 Rustup 及其管理的所有工具链,并恢复 PATH 环境变量的更改。

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’
804.2 KiB / 804.2 KiB (100 %) 86.3 KiB/s in 10s ETA: 0s info: latest update on 2024-09-05, rust version 1.81.0 (eeb90cda1 2024-09-04) info:
downloading component ‘cargo’
8.3 MiB / 8.3 MiB (100 %) 243.2 KiB/s in 43s ETA: 0s info: downloading component ‘clippy’
2.6 MiB / 2.6 MiB (100 %) 488.2 KiB/s in 8s ETA: 0s info: downloading component ‘rust-docs’
15.9 MiB / 15.9 MiB (100 %) 962.2 KiB/s in 1m 13s ETA: 0s info: downloading component ‘rust-std’
26.8 MiB / 26.8 MiB (100 %) 298.8 KiB/s in 1m 37s ETA: 0s info: downloading component ‘rustc’
66.9 MiB / 66.9 MiB (100 %) 198.4 KiB/s in 9m 28s ETA: 0s info: downloading component ‘rustfmt’
2.4 MiB / 2.4 MiB (100 %) 438.4 KiB/s in 8s ETA: 0s info: installing component ‘cargo’ info: installing component ‘clippy’ info:
installing component ‘rust-docs’
15.9 MiB / 15.9 MiB (100 %) 5.8 MiB/s in 2s ETA: 0s info: installing component ‘rust-std’
26.8 MiB / 26.8 MiB (100 %) 14.7 MiB/s in 2s ETA: 0s info: installing component ‘rustc’
66.9 MiB / 66.9 MiB (100 %) 15.7 MiB/s in 4s 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.81.0 (eeb90cda1
2024-09-04)

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, you need to source the corresponding
env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading
DOT): . “KaTeX parse error: Expected 'EOF', got '#' at position 29: …nv" #̲ For sh/bash/zs…HOME/.cargo/env.fish” # For fish
这个输出是关于在终端中安装 Rust 的详细日志。每一行解释如下:

  1. info: profile set to ‘default’
    Rust 安装时选择了默认的配置(profile),这意味着 Rust 会根据默认的设置安装其组件。这通常包括常用的工具,比如编译器和包管理器。

  2. info: default host triple is x86_64-unknown-linux-gnu
    这是 Rust 编译器的目标平台,也叫“三元组”(triple),这里指的是 64 位的 Linux 系统。x86_64-unknown-linux-gnu 表示编译器将生成适用于 64 位 Linux 系统的代码。

  3. info: syncing channel updates for ‘stable-x86_64-unknown-linux-gnu’
    Rust 的安装器正在同步最新的稳定版(stable channel)更新。这意味着它正在获取当前最新版本的稳定版 Rust 相关组件。

  4. 下载组件(cargo, clippy, rust-docs, rust-std, rustc, rustfmt)

    • cargo 是 Rust 的包管理工具,用于管理依赖和构建项目。
    • clippy 是一个 Rust 代码的静态分析工具,帮助开发者遵循最佳实践。
    • rust-docs 是 Rust 的文档,可以离线访问 Rust 标准库的文档。
    • rust-std 是标准库,Rust 编译时所需要的核心库。
    • rustc 是 Rust 编译器,负责将 Rust 源代码编译为可执行文件。
    • rustfmt 是代码格式化工具,用于确保 Rust 代码风格的一致性。
  5. info: installing component ‘cargo’
    系统开始安装上述下载的组件,如 cargoclippyrust-docs 等。

  6. info: default toolchain set to ‘stable-x86_64-unknown-linux-gnu’
    系统设置了默认的 Rust 工具链为稳定版,即用户将使用稳定版的 Rust 编译器和工具。

  7. Rust is installed now. Great!
    Rust 安装成功,已经准备好使用。

  8. To get started you may need to restart your current shell.
    建议用户重启当前的终端会话,或重新加载终端,以确保 $HOME/.cargo/bin 路径被正确添加到 PATH 环境变量中。

  9. To configure your current shell, you need to source…
    这一行提示如何在当前 shell 中手动加载 Rust 环境,可以运行以下命令:

    . "$HOME/.cargo/env"    # 对于 bash、zsh 等 shell
    

    或者:

    source "$HOME/.cargo/env.fish"  # 对于 fish shell
    

通过这些步骤,Rust 及其工具链已经成功安装,可以开始使用 Rust 开发了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2182302.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

昇思MindSpore进阶教程--下沉模式

大家好,我是刘明,明志科技创始人,华为昇思MindSpore布道师。 技术上主攻前端开发、鸿蒙开发和AI算法研究。 努力为大家带来持续的技术分享,如果你也喜欢我的文章,就点个关注吧 正文开始 昇腾芯片集成了AICORE和AICPU等…

C#自定义工具类-数组工具类

目录 数组工具类基本操作 1.排序:升序,降序 2.查找 1)查找最值:最大值,最小值 2)查找满足条件的单个对象 3)查找满足条件的所有对象 4)选取数组中所有对象的某一字段 完整代…

河南做网站与SEO:如何提升搜索引擎排名

河南做网站与SEO:如何提升搜索引擎排名 在当今数字化时代,越来越多的企业意识到互联网的重要性,特别是在河南这样一个快速发展的地区,建立一个优秀的网站已经成为企业发展的必要条件。而在建立网站的同时,SEO&#xff…

--- java数据结构 map set ---

java中map 和 set的底层实现是通过搜索树和哈希函桶来实现 搜索树 二叉搜索树有叫二叉排序树 他具有以下的特点 若存在左节点,那么他左节点的值一定小于根节点 若存在右节点,那么他右节点的值一定大于根节点 它的左右子树也是搜索树 对他进行中序…

leetcode热题100.最长公共子序列

题目 1143. 最长公共子序列 - 力扣(LeetCode) 给定两个字符串 text1 和 text2,返回这两个字符串的最长 公共子序列 的长度。如果不存在 公共子序列 ,返回 0 。 一个字符串的 子序列 是指这样一个新的字符串:它是由原…

SOMEIP_ETS_143: SD_Request_non_existing_ServiceID

测试目的: 验证DUT能够拒绝一个请求不存在的服务ID(ServiceID)的SubscribeEventgroup消息,并以SubscribeEventgroupNAck作为响应。 描述 本测试用例旨在确保DUT遵循SOME/IP协议,当接收到一个请求不存在服务ID的Subs…

RS485串口通信:【图文详讲】

RS485,RS的意义为Recommended Standard的缩写,也就是推荐标准,是一种常用的半双工-异步-串行通信总线。半双工的意思就是两者通信时,同一时刻,只能由其中一方发送,另一方只能接收,不可以同时收发…

vue3 antdv3/4 Modal显示一个提示,内容换行显示。

1、官网地址: Ant Design Vue — An enterprise-class UI components based on Ant Design and Vue.js 2、显示个信息: Modal.info({title: This is a notification message,content: h(div, {}, [h(p, some messages...some messages...),h(p, some …

基于解压缩模块的JPEG同步重压缩检测论文学习

一、论文基本信息: 论文题目:基于解压缩模块的JPEG同步重压缩检测 作者:王金伟1 ,胡冰涛1 ,张家伟1 ,马 宾2 ,罗向阳3 (1.南京信息工程大学计算机学院、网络空间安全学院&#xf…

Linux-L11-查看本机ip地址

linux查看ip地址 查看自己的IP地址使用 ip 命令:使用 ifconfig 命令使用 hostname 命令:使用 nmcli 命令 查看某个特定接口的IP查看公网IP地址 在Linux系统中,查看自己的IP地址可以通过多种方式实现,这里提供几种常用的方法&#…

Stable Diffusion绘画 | LCM模型:实现秒出图

在过往,不管使用 SD 还是 MJ,生成一张图片起码要等上10秒。 而现在,有了 LCM 技术的加持,已经能做到秒出图,甚至是实时出图。 LCM(潜空间一致性模型) 是由 清华大学信息科学技术研究院 研发的大模型,它最…

鸿蒙 如何退出 APP

terminateSelf() 停止Ability自身 在EntryAbility中这么使用 this.context.terminateSelf()在Pages页面中这么使用 import { common } from kit.AbilityKit (getContext(this) as common.UIAbilityContext)?.terminateSelf() 也可以直接封装: import common f…

【GreenHills】GHS的Run-Time检查功能

【更多软件使用问题请点击亿道电子官方网站】 一、文档背景 在编写代码时,内存检查的重要性不容忽视。内存是程序运行的核心资源之一,负责存储程序运行所需的数据。由于内存资源的有限性和操作的复杂性,内存错误常常会直接导致程序崩溃、性…

华为开源自研AI框架昇思MindSpore应用案例:基于MindSpore框架的Swin Transformer

如果你对MindSpore感兴趣,可以关注昇思MindSpore社区 模型简介 模型背景 Swin Transfromer在2021年首次发表于论文《Swin Transformer: Hierarchical Vision Transformer using Shifted Windows》,目前已用于图像分割、分类等计算机视觉领域的各项任务…

如何搭建医疗陪诊平台?基于互联网医院系统源码的开发技术详解

本篇文章,小编将深入探讨医疗陪诊平台的搭建过程,尤其是基于互联网医院系统源码的开发技术,以期为有志于此领域的开发者提供参考。 一、选择合适的互联网医院系统源码 在搭建医疗陪诊平台时,选择合适的互联网医院系统源码至关重…

【前端开发入门】前端开发环境配置

目录 引言一、Vscode编辑器安装1. 软件下载2. 软件安装3. 插件安装 二、Nodejs环境安装及版本控制1. 安装内容2. 使用nvm安装2.1 软件下载并安装2.2 nvm基本指令2.3 nvm下载过慢导致超时解决 三、git安装及配置1. 软件下载2. 软件安装3. 基础配置 四、总结 引言 本系列教程旨在…

SRC漏洞挖掘 | 针对Spring-Boot 框架漏洞的初探

💗想加内部圈子,请联系我! 💗文章交流,请联系我!🍬 博主介绍 👨‍🎓 博主介绍:大家好,我是 一个想当文人的黑客 ,很高兴认识大家~ ✨主…

fmt:C++ 格式化库

fmt 是一个现代化、快速且安全的 C 格式化库,专注于高效地格式化文本。它提供了类似 Python 的 format 功能,但具有更高的性能和类型安全特性。fmt 库在处理字符串格式化、日志输出以及构建用户友好的输出时尤为强大。自从 C20 标准引入 std::format 后&…

文章解读与仿真程序复现思路——电网技术EI\CSCD\北大核心《故障扰动下的风火储送端系统频率动态特性与储能容量优化配置》

本专栏栏目提供文章与程序复现思路,具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源…

婚前协议模版(琴生生物机械科技工业研究所)

婚前协议示例 本协议由甲方(全名),身份证号码( _________ ),与乙方(全名),身份证号码( _________ ),在平等、自愿、相互尊重及充分沟…