RustUp aka How to install rust the convenient way

As I usually do when installing new languages, I looked for a version manager for Rust.

Rust has a rather nice one, called rustup, which lets you switch from nightly to stable, and to different targets with very little effort.

Install RustUp

If you are on a Mac or Linux machine, this should do it:

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

Channels

Now you hopefully have RustUp, one thing you should know is there are three versions of Rust you can use with rustup:

  • stable
  • beta
  • nightly
Commands
  • rustup install <version> will install the one you want
  • rustup default stable will set the one you can access by default to be the stable one.
Test install

Now you should have rustc, cargo and rustdoc.

$ rustc --version
rustc 1.9.0 (e4e8b6668 2016-05-18)

Overrides

If you want a very specific version in a specific directory, you can:

$ cd <projectdir>
$ rustup override <version>

Example:

$ rustup override add nightly-2014-12-18
$ rustup override add 1.0.0

You can check if there are overrides with rustup show and remove them with rustup override remove.

You can also temporarily use a specific version just for one command, by prepending rustup run <version> <command>:

$ rustup run beta bash

will open a beta shell.

Keeping up to date

$ rustup update

will update all your rust installs.

Better autocomplete

cargo install racer for better completion.

You'll also need to clone the rust source code from git in some directory, then set RUST_SRC_PATH to that directory.

To test it actually works, try:

$ racer complete std::io::B
MATCH BufReader,48,11,/Users/<user>/.rust/rust/src/libstd/io/buffered.rs,Struct,pub struct BufReader<R>
...

Emacs

I use terminal emacs and rust-mode works like a charm.

You'll need to install rust-mode and racer with M-x package-list-packages.

What I have in my .emacs:

(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'company-mode)
(add-hook 'rust-mode-hook
          '(lambda ()
             (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)
                          (local-set-key (kbd "TAB") #'company-indent-or-complete-common)))
(setq racer-rust-src-path (getenv "RUST_SRC_PATH"))
(global-set-key (kbd "TAB") #'company-indent-or-complete-common) ;
(setq company-tooltip-align-annotations t)

More Toolchains

rustup, the successor of multirust can also manage multiple and custom toolchains for cross-compilation.

$ rustup target list

to get a list of the available targets.

More info in the docs.

Gotchas

If you have multirust installed, you might have to wipe it out completely before RustUp works.

So now you should have a pretty nice dev env for Rust (assuming you like emacs).
Happy coding!