Installation

The first step to using Rust is to install it. You’ll need an internet connection to run the commands in this chapter, as we’ll be downloading Rust from the internet.

We’ll be showing off a number of commands using a terminal, and those lines all start with $. You don’t need to type in the $ character; they are there to indicate the start of each command. You’ll see many tutorials and examples around the web that follow this convention: $ for commands run as a regular user, and # for commands you should be running as an administrator. Lines that don’t start with $ are typically showing the output of the previous command.

Installing on Linux or Mac

If you’re on Linux or a Mac, all you need to do is open a terminal and type this:

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

This will download a script and start the installation. You may be prompted for your password. If it all goes well, you’ll see this appear:

Rust is installed now. Great!

Of course, if you disapprove of the curl | sh pattern, you can download, inspect and run the script however you like.

The installation script automatically adds Rust to your system PATH after your next login. If you want to start using Rust right away, run the following command in your shell:

$ source $HOME/.cargo/env

Alternatively, add the following line to your ~/.bash_profile:

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

Installing on Windows

On Windows, go to https://rustup.rs and follow the instructions to download rustup-init.exe. Run that and follow the rest of the instructions it gives you.

The rest of the Windows-specific commands in the book will assume that you are using cmd as your shell. If you use a different shell, you may be able to run the same commands that Linux and Mac users do. If neither work, consult the documentation for the shell you are using.

Custom installations

If you have reasons for preferring not to use rustup.rs, please see the Rust installation page for other options.

Updating

Once you have Rust installed, updating to the latest version is easy. From your shell, run the update script:

$ rustup update

Uninstalling

Uninstalling Rust is as easy as installing it. From your shell, run the uninstall script:

$ rustup self uninstall

Troubleshooting

If you’ve got Rust installed, you can open up a shell, and type this:

$ rustc --version

You should see the version number, commit hash, and commit date in a format similar to this for the latest stable version at the time you install:

rustc x.y.z (abcabcabc yyyy-mm-dd)

If you see this, Rust has been installed successfully! Congrats!

If you don’t and you’re on Windows, check that Rust is in your %PATH% system variable.

If it still isn’t working, there are a number of places where you can get help. The easiest is the #rust IRC channel on irc.mozilla.org, which you can access through Mibbit. Go to that address, and you’ll be chatting with other Rustaceans (a silly nickname we call ourselves) who can help you out. Other great resources include the Users forum and Stack Overflow.

Local documentation

The installer also includes a copy of the documentation locally, so you can read it offline. Run rustup doc to open the local documentation in your browser.

Any time there’s a type or function provided by the standard library and you’re not sure what it does, use the API documentation to find out!

results matching ""

    No results matching ""