RustPrimer
  • Introduction
  • 初识Rust
  • 安装Rust
    • Linux
    • Mac
    • Windows
    • 版本管理工具: rustup
  • 编辑器
    • 前期准备
    • vim
    • emacs
    • vscode
    • atom
    • sublime
    • visual studio
    • spacemacs
  • Rust快速入门
    • Rust旅程
    • 变量绑定与原生类型
    • 数组、动态数组和字符串
    • 结构体与枚举
    • 控制流
    • 函数与方法
    • 特性
    • 注释与文档
    • 输入输出流
  • Cargo项目管理器
  • 基本程序结构
    • 注释
    • 条件
    • 循环
  • 类型、运算符和字符串
    • 基础类型
    • 复合类型
    • 字符串类
    • 基础运算符和字符串格式化
  • 函数
    • 函数参数
    • 函数返回值
    • 语句和表达式
    • 高阶函数
  • 模式匹配
    • match关键字
    • 模式 pattern
  • 特征 Trait
    • trait关键字
    • trait对象
  • 泛型
  • 可变性、所有权、租借和生命期
    • 所有权
    • 引用和借用
    • 生命周期
  • 闭包
    • 闭包的语法
    • 闭包的实现
    • 闭包作为参数和返回值
  • 集合类型 Collections
    • 动态数组 Vec
    • 哈希表 HashMap
  • 迭代器
    • 迭代器、适配器、消费者
  • 模块和包系统、Prelude
    • 模块 module 和包 crate
    • Prelude
  • Option、Result与错误处理
  • 输入与输出
  • 宏系统
  • 堆、栈与Box
  • 几种智能指针
    • Rc, Arc
    • Mutex, RwLock
    • Cell, RefCell
  • 类型系统中的几个常见 Trait
    • Into/From 及其在 String 和 &str 互转上的应用
    • AsRef, AsMut
    • Borrow, BorrowMut, ToOwned
    • Deref 与 Deref coercions
    • Cow 及其在 String 和 &str 上的应用
  • Send 和 Sync
  • 并发,并行,多线程编程
    • 线程
    • 消息传递
    • 共享内存
    • 同步
    • 并行
  • Unsafe、原始指针
    • Unsafe
    • 原始指针
  • FFI
    • rust调用ffi函数
    • 将rust编译成库
  • 运算符重载
  • 属性和编译器参数
    • 属性
    • 编译器参数
  • Cargo参数配置
  • 测试与评测
    • 测试 (testing)
    • 评测 (benchmark)
  • 代码风格
  • Any与反射
  • 安全(safe)
  • 常用数据结构实现
    • 栈结构
    • 队列
    • 二叉树
    • 优先队列
    • 链表
    • 图结构
  • 标准库介绍
    • 系统命令:调用grep
    • 目录操作:简单grep
    • 网络模块:W回音
  • 实战篇
    • 实战:Json处理
    • 实战:Web 应用开发入门
    • 实战:使用Postgresql数据库
  • 附录-术语表
Powered by GitBook
On this page
  • Features
  • 安装
  • Windows
  • Linux & OSX
  • 卸载
  • 用法
  • 帮助

Was this helpful?

  1. 安装Rust

版本管理工具: rustup

PreviousWindowsNext编辑器

Last updated 5 years ago

Was this helpful?

rustup 是rust官方的版本管理工具。

项目主页是:

Features

  • 管理安装多个官方版本的 Rust 二进制程序。

  • 配置基于目录的 Rust 工具链。

  • 安装和更新来自 Rust 的发布通道: nightly, beta 和 stable。

  • 接收来自发布通道更新的通知。

  • 从官方安装历史版本的 nightly 工具链。

  • 通过指定 stable 版本来安装。

  • 安装额外的 std 用于交叉编译。

  • 安装自定义的工具链。

  • 独立每个安装的 Cargo metadata。

  • 校验下载的 hash 值。

  • 校验签名 (如果 GPG 存在)。

  • 断点续传。

  • 只依赖 bash, curl 和常见 unix 工具。

  • 支持 Linux, OS X, Windows(via MSYS2)。

安装

Windows

在Windows下工具链会安装到%USERPROFILE%\.cargo\bin文件夹下并添加到$PATH环境变量。

Linux & OSX

运行以下命令

curl https://sh.rustup.rs -sSf | sh

这个命令将会编译和安装 rustup, 安装过程中可能会提示你输入 sudo 的密码。 然后, 他会下载和安装 stable 版本的工具链, 当执行 rustc, rustdoc 和 cargo 时, 将会配置他为默认工具链。

Unix 上安装后工具链会被安装到 $HOME/.cargo/bin目录。

.cargo/bin目录会被添加到系统的$PATH环境变量,重新登录后即可使用rustc,cargo等命令。

卸载

rustup self uninstall

用法

安装后会得到一个 rustup 命令, 多使用命令自带的帮助提示, 可以快速定位你需要功能。

帮助

运行 rustup -h 你将会得到如下提示:

❯ rustup -h
#rustup 0.1.12 (c6e430a 2016-05-12)
#The Rust toolchain installer
#
#USAGE:
#    rustup [FLAGS] [SUBCOMMAND]
#
#FLAGS:
#    -v, --verbose    Enable verbose output
#    -h, --help       Prints help information
#    -V, --version    Prints version information
#
#SUBCOMMANDS:
#    show         Show the active and installed toolchains
#    update       Update Rust toolchains
#    default      Set the default toolchain
#    toolchain    Modify or query the installed toolchains
#    target       Modify a toolchain's supported targets
#    override     Modify directory toolchain overrides
#    run          Run a command with an environment configured for a given toolchain
#    which        Display which binary will be run for a given command
#    doc          Open the documentation for the current toolchain.
#    self         Modify the rustup installation
#    telemetry    rustup telemetry commands
#    help         Prints this message or the help of the given subcommand(s)
#
#rustup installs The Rust Programming Language from the official
#release channels, enabling you to easily switch between stable, beta,
#and nightly compilers and keep them updated. It makes cross-compiling
#simpler with binary builds of the standard library for common platforms.
#
#If you are new to Rust consider running `rustup doc --book`
#to learn Rust.

根据提示, 使用 rust help <command> 来查看子命令的帮助, 基本看这些帮助文档就足够了。

我们可以使用rustup default <toolchain> 配置默认的工具链。

其中标准的 <toolchain>具有如下的形式 <channel>[-<date>][-<host>]

<channel>       = stable|beta|nightly|<version>
<date>          = YYYY-MM-DD
<host>          = <target-triple>

如stable-x86_64-pc-windows-msvc nightly-2014-12-18 1.8.0等都是合法的toolchain名称。

下面着重介绍几个常用的命令。

rustup override add <toolchain> 添加一个目录以及其子目录的默认工具链。

rustup override remove <toolchain> 删除一个目录以及其子目录的默认工具链。

rustup show 显示当前安装的工具链信息。

rustup toolchain install <toolchain> 安装特定的的工具链。

rustup toolchain link <toolchain-name> "<toolchain-path>" 设置自定义工具链。

rustup target add <target> 设置工具链的可用目标。

rustup update 检查安装工具链的更新。

在下载并运行rustup-init.exe,并按照提示选择选项。

我们也可以采用配合rustup。

https://github.com/rust-lang-nursery/rustup.rs
rustup的主页
自定义toolchain