As with most languages, Rust is available for a wide number of platforms. It would be impossible to go through installing the compiler on every variant of every operating system. Fortunately, there's an official method of installing Rust, and even though the details may differ slightly, the process is almost the same on all platforms. Therefore, this book will cover installing Rust using rustup on Fedora 27.
https://rustup.rs always contains up-to-date instructions on how to get going on all platforms. On Linux and macOS, it will look something like this:
On Windows, this text is replaced by a link to rustup-init.exe
, which is an executable that installs and sets up rustup on Windows.
Run the suggested command that is shown at https://rustup.rs. Run this command in a Terminal. The script suggests some defaults and asks you to confirm them. This is roughly what it should look like after completing the whole script:
Note that this script attempts to set up rustup for your user by editing your .profile
and .bash_profile
files. If you are using a custom setup, such as another shell, you may need to add the source $HOME/.cargo/env
command manually.
After finishing this script, you can verify that it worked by logging off and on from your Terminal and verifying that the tools are in your path:
To build any software that links against external libraries, you will need a C compiler and development versions of any libraries you may be linking against. To ensure that things work properly, install the compiler using the standard method for your operating system.
In Fedora, this would be done using the dnf
tool:
sudo dnf install -y gcc
If you are unsure whether you have gcc installed, type the following command in a terminal window:
gcc -version
If gcc is installed, you'll see something like this:
To effectively code Rust, you will need at least some sort of text editor. All popular editors are properly supported, so if your favorite is Vim, Emacs, or any of the others, you will find a high-quality Rust extension there. The website https://areweideyet.com/ should give a current view of how things are.
We will cover the lightweight IDE from Microsoft, Visual Studio Code, and its most current Rust extension, called simply Rust. This IDE should work fairly well in all the different desktop environments. Installation instructions and packages for several platforms are available at Visual Studio Code's main site, https://code.visualstudio.com.
- Open up
Visual Studio Code
and go to the Command Palette, either by theView
menu or by the keyboard shortcut Ctrl + Shift + P (which may differ between platforms). Type ininstall extension
to look for the proper command, and then selectInstall Extensions
:
- After selecting this, type
rust
into the next field to look for theRust
extension. At the time of writing, the most recent one is made by kalitaalexey:
- You can install Rust right away by pressing
Install
; alternatively, click on the list item itself to show information about the extension first. After installing it, reload the editor. TheRust
extension is now installed and ready to use!