]> git.proxmox.com Git - rustc.git/blame - src/doc/edition-guide/src/rust-2018/rustup-for-managing-rust-versions.md
New upstream version 1.41.1+dfsg1
[rustc.git] / src / doc / edition-guide / src / rust-2018 / rustup-for-managing-rust-versions.md
CommitLineData
450edc1f
XL
1# Rustup for managing Rust versions
2
3![Minimum Rust version: various](https://img.shields.io/badge/Minimum%20Rust%20Version-various-brightgreen.svg) (this tool has its own versioning scheme and works with all Rust versions)
4
5The [Rustup](https://rustup.rs/) tool has become *the* recommended way to
6install Rust, and is advertised on our website. Its powers go further than
7that though, allowing you to manage various versions, components, and
8platforms.
9
10## For installing Rust
11
12To install Rust through Rustup, you can go to
13<https://www.rust-lang.org/install.html>, which will let you know how to do
14so on your platform. This will install both `rustup` itself and the `stable`
15version of `rustc` and `cargo`.
16
17To install a specific Rust version, you can use `rustup install`:
18
19```console
20$ rustup install 1.30.0
21```
22
23This works for a specific nightly, as well:
24
25```console
26$ rustup install nightly-2018-08-01
27```
28
29As well as any of our release channels:
30
31```console
32$ rustup install stable
33$ rustup install beta
34$ rustup install nightly
35```
36
37## For updating your installation
38
39To update all of the various channels you may have installed:
40
41```console
42$ rustup update
43```
44
45This will look at everything you've installed, and if there are new releases,
46will update anything that has one.
47
48## Managing versions
49
50To set the default toolchain to something other than `stable`:
51
52```console
48663c56 53$ rustup default nightly
450edc1f
XL
54```
55
56To use a toolchain other than the default, use `rustup run`:
57
58```console
59$ rustup run nightly cargo build
60```
61
62There's also an alias for this that's a little shorter:
63
64```console
65$ cargo +nightly build
66```
67
68If you'd like to have a different default per-directory, that's easy too!
69If you run this inside of a project:
70
71```console
72$ rustup override set nightly
73```
74
532ac7d7
XL
75Or, if you'd like to target a different version of Rust:
76```console
77$ rustup override set 1.30.0
78```
79
450edc1f
XL
80Then when you're in that directory, any invocations of `rustc` or `cargo`
81will use that toolchain. To share this with others, you can create a
82`rust-toolchain` file with the contents of a toolchain, and check it into
83source control. Now, when someone clones your project, they'll get the
84right version without needing to `override set` themselves.
85
86## Installing other targets
87
88Rust supports cross-compiling to other targets, and Rustup can help you
89manage them. For example, to use MUSL:
90
91```console
92$ rustup target add x86_64-unknown-linux-musl
93```
94
95And then you can
96
97```console
98$ cargo build --target=x86_64-unknown-linux-musl
99```
100
101To see the full list of targets you can install:
102
103```console
104$ rustup target list
105```
106
107## Installing components
108
109Components are used to install certain kinds of tools. While `cargo-install`
110has you covered for most tools, some tools need deep integration into the
111compiler. Rustup knows exactly what version of the compiler you're using, and
112so it's got just the information that these tools need.
113
114Components are per-toolchain, so if you want them to be available to more
115than one toolchain, you'll need to install them multiple times. In the
116following examples, add a `--toolchain` flag, set to the toolchain you
117want to install for, `nightly` for example. Without this flag, it will
118install the component for the default toolchain.
119
120To see the full list of components you can install:
121
122```console
123$ rustup component list
124```
125
126Next, let's talk about some popular components and when you might want to
127install them.
128
129### `rust-docs`, for local documentation
130
131This first component is installed by default when you install a toolchain. It
132contains a copy of Rust's documentation, so that you can read it offline.
133
134This component cannot be removed for now; if that's of interest, please
135comment on [this
60c5eb7d 136issue](https://github.com/rust-lang/rustup.rs/issues/998).
450edc1f
XL
137
138### `rust-src` for a copy of Rust's source code
139
140The `rust-src` component can give you a local copy of Rust's source code. Why
141might you need this? Well, autocompletion tools like Racer use this
142information to know more about the functions you're trying to call.
143
144```console
145$ rustup component add rust-src
146```
147
416331ca 148### `rustfmt` for automatic code formatting
450edc1f
XL
149
150![Minimum Rust version: 1.24](https://img.shields.io/badge/Minimum%20Rust%20Version-1.24-brightgreen.svg)
151
152If you'd like to have your code automatically formatted, you can
153install this component:
154
155```console
416331ca 156$ rustup component add rustfmt
450edc1f
XL
157```
158
159This will install two tools, `rustfmt` and `cargo-fmt`, that will reformat your
160code for you! For example:
161
162```console
163$ cargo fmt
164```
165
166will reformat your entire Cargo project.
167
416331ca 168### `rls` for IDE integration
450edc1f
XL
169
170![Minimum Rust version: 1.21](https://img.shields.io/badge/Minimum%20Rust%20Version-1.21-brightgreen.svg)
171
172Many IDE features are built off of the [`langserver`
173protocol](http://langserver.org/). To gain support for Rust with these IDEs,
174you'll need to install the Rust language sever, aka the "RLS":
175
176```console
416331ca 177$ rustup component add rls
450edc1f
XL
178```
179
416331ca
XL
180For more information about integrating this into your IDE, see the [RLS
181documentation](https://github.com/rust-lang/rls).
450edc1f 182
416331ca 183### `clippy` for more lints
450edc1f
XL
184
185For even more lints to help you write Rust code, you can install `clippy`:
186
187```console
416331ca 188$ rustup component add clippy
450edc1f
XL
189```
190
191This will install `cargo-clippy` for you:
192
193```console
194$ cargo clippy
195```
196
197For more, check out [clippy's
416331ca
XL
198documentation](https://github.com/rust-lang/rust-clippy).
199
200### The "preview" components
201
202There are several components in a "preview" stage. These components currently
203have `-preview` in their name, and this indicates that they're not quite 100%
204ready for general consumption yet. Please try them out and give us feedback,
205but know that they do not follow Rust's stability guarantees, and are still
206actively changing, possibly in backwards-incompatible ways.
450edc1f
XL
207
208#### `llvm-tools-preview` for using extra LLVM tools
209
210If you'd like to use the `lld` linker, or other tools like `llvm-objdump` or
211`llvm-objcopy`, you can install this component:
212
213```console
214$ rustup component add llvm-tools-preview
215```
216
217This is the newest component, and so doesn't have good documentation at the
532ac7d7 218moment.