translated

This commit is contained in:
geekpi 2022-06-27 08:40:52 +08:00
parent a1540bc8f0
commit 24e8492593
2 changed files with 143 additions and 143 deletions

View File

@ -1,143 +0,0 @@
[#]: subject: "Manage your Rust toolchain using rustup"
[#]: via: "https://opensource.com/article/22/6/rust-toolchain-rustup"
[#]: author: "Gaurav Kamathe https://opensource.com/users/gkamathe"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Manage your Rust toolchain using rustup
======
Rustup can be used to install Rust and keep it updated. It also allows you to seamlessly switch between the stable, beta, and nightly Rust compilers and tooling.
![Tools illustration][1]
Image by: Opensource.com
The [Rust programming language][2] is becoming increasingly popular these days, used and loved by hobbyists and corporations alike. One of the reasons for its popularity is the amazing tooling that Rust provides making it a joy to use for developers. [Rustup][3] is the official tool used to manage Rust tooling. Not only can it be used to install Rust and keep it updated, it also allows you to seamlessly switch between the stable, beta, and nightly Rust compilers and tooling. This article will introduce you to rustup and some common commands to use.
### Default Rust installation method
If you want to install Rust on Linux, you can use your package manager. On Fedora or CentOS Stream you can use this, for example:
```
$ sudo dnf install rust cargo
```
This provides a stable version of the Rust toolchain, and works great if you are a beginner to Rust and want to try compiling and running simple programs. However, because Rust is a new programming language it changes fast and a lot of new features are frequently added. These features are part of the nightly and later beta version of the Rust toolchain. To try out these features you need to install these newer versions of the toolchain, without affecting the stable version on the system. Unfortunately, your distros package manager cant help you here.
### Installing Rust toolchain using rustup
To get around the above issues, you can download an install script:
```
$ curl --proto '=https' --tlsv1.2 \
-sSf https://sh.rustup.rs > sh.rustup.rs
```
Inspect it, and then run it. It doesnt require root privileges and installs Rust accordingly to your local user privileges:
```
$ file sh.rustup.rs
sh.rustup.rs: POSIX shell script, ASCII text executable
$ less sh.rustup.rs
$ bash sh.rustup.rs
```
Select option 1 when prompted:
```
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
> 1
```
After installation, you must source the environment variables to ensure that the `rustup` command is immediately available for you to use:
```
$ source $HOME/.cargo/env
```
Verify that the Rust compiler (rustc) and Rust package manager (cargo) are installed:
```
$ rustc --version
$ cargo --version
```
### See installed and active toolchains
You can view the different toolchains that were installed and which one is the active one using the following command:
```
$ rustup show
```
### Switch between toolchains
You can view the default toolchain and change it as required. If youre currently on a stable toolchain and wish to try out a newly introduced feature that is available in the nightly version you can easily switch to the nightly toolchain:
```
$ rustup default
$ rustup default nightly
```
To see the exact path of the compiler and package manager of Rust:
```
$ rustup which rustc
$ rustup which cargo
```
### Checking and Updating the toolchain
To check whether a new Rust toolchain is available:
```
$ rustup check
```
Suppose a new version of Rust is released with some interesting features, and you want to get the latest version of Rust. You can do that with the `update` subcommand:
```
$ rustup update
```
### Help and documentation
The above commands are more than sufficient for day-to-day use. Nonetheless, rustup has a variety of commands and you can refer to the help section for additional details:
```
$ rustup --help
```
Rustup has an entire [book][4] on GitHub that you can use as a reference. All the Rust documentation is installed on your local system, which does not require you to be connected to the Internet. You can access the local documentation which includes the book, standard library, and so on:
```
$ rustup doc
$ rustup doc --book
$ rustup doc --std
$ rustup doc --cargo
```
Rust is an exciting language under active development. If youre interested in where programming is headed, keep up with Rust!
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/6/rust-toolchain-rustup
作者:[Gaurav Kamathe][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/gkamathe
[b]: https://github.com/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/tools_hardware_purple.png
[2]: https://www.rust-lang.org/
[3]: https://github.com/rust-lang/rustup
[4]: https://rust-lang.github.io/rustup/

View File

@ -0,0 +1,143 @@
[#]: subject: "Manage your Rust toolchain using rustup"
[#]: via: "https://opensource.com/article/22/6/rust-toolchain-rustup"
[#]: author: "Gaurav Kamathe https://opensource.com/users/gkamathe"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
使用 rustup 管理你的 Rust 工具链
======
Rustup 可用于安装 Rust 并保持更新。它还允许你在稳定版、测试版和每日 Rust 编译器和工具之间无缝切换。
![Tools illustration][1]
图片来源Opensource.com
[Rust 编程语言][2] 如今变得越来越流行,受到爱好者和公司的一致好评。它受欢迎的原因之一是 Rust 提供的令人惊叹的工具使其成为开发人员使用的乐趣。 [Rustup][3] 是用于管理 Rust 工具的官方工具。它不仅可以用于安装 Rust 并保持更新,它还允许你在稳定、测试和每日 Rust 编译器和工具之间无缝切换。本文将向你介绍 rustup 和一些常用命令。
### 默认 Rust 安装方式
如果你想在 Linux 上安装 Rust你可以使用你的包管理器。在 Fedora 或 CentOS Stream 上,你可以这样使用它,例如:
```
$ sudo dnf install rust cargo
```
这提供了一个稳定版本的 Rust 工具链,如果你是 Rust 的初学者并想尝试编译和运行简单的程序,它会非常有用。但是,由于 Rust 是一种新的编程语言,它变化很快,并且经常添加许多新功能。这些功能是 Rust 工具链的每日和之后测试版的一部分。要试用这些功能,你需要安装这些较新版本的工具链,而不会影响系统上的稳定版本。不幸的是,你的发行版的包管理器在这里无法为你提供帮助。
### 使用 rustup 安装 Rust 工具链
要解决上述问题,你可以下载安装脚本:
```
$ curl --proto '=https' --tlsv1.2 \
-sSf https://sh.rustup.rs > sh.rustup.rs
```
检查它,然后运行它。它不需要 root 权限,并根据你的本地用户权限安装 Rust
```
$ file sh.rustup.rs
sh.rustup.rs: POSIX shell script, ASCII text executable
$ less sh.rustup.rs
$ bash sh.rustup.rs
```
出现提示时选择选项 1
```
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
> 1
```
安装后,你必须获取环境变量以确保 `rustup` 命令立即可供你使用:
```
$ source $HOME/.cargo/env
```
验证是否安装了 Rust 编译器 (rustc) 和 Rust 包管理器 (cargo)
```
$ rustc --version
$ cargo --version
```
### 查看已安装和活动的工具链
你可以使用以下命令查看已安装的不同工具链以及哪个工具链是活动的:
```
$ rustup show
```
### 在工具链之间切换
你可以查看默认工具链并根据需要进行更改。如果你当前使用的是稳定的工具链,并希望尝试每日版本中提供的新功能,你可以轻松切换到每日工具链:
```
$ rustup default
$ rustup default nightly
```
要查看 Rust 的编译器和包管理器的确切路径:
```
$ rustup which rustc
$ rustup which cargo
```
### 检查和更新工具链
要检查是否有新的 Rust 工具链可用:
```
$ rustup check
```
假设一个新版本的 Rust 发布了,其中包含一些有趣的特性,并且你想要获取最新版本的 Rust。你可以使用 `update` 子命令来做到这一点:
```
$ rustup update
```
### 帮助和文档
以上命令对于日常使用来说绰绰有余。尽管如此rustup 有多种命令,你可以参考帮助部分了解更多详细信息:
```
$ rustup --help
```
Rustup 在 GitHub 上有完整的[说明书][4],你可以将其用作参考。所有 Rust 文档都安装在你的本地系统上,不需要你连接到 Internet。你可以访问包括书籍、标准库等在内的本地文档
```
$ rustup doc
$ rustup doc --book
$ rustup doc --std
$ rustup doc --cargo
```
Rust 是一种正在积极开发中的令人兴奋的语言。如果你对编程的发展方向感兴趣,请关注 Rust
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/6/rust-toolchain-rustup
作者:[Gaurav Kamathe][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/gkamathe
[b]: https://github.com/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/tools_hardware_purple.png
[2]: https://www.rust-lang.org/
[3]: https://github.com/rust-lang/rustup
[4]: https://rust-lang.github.io/rustup/