We will explore ways in which we can install Rust components in Linux and macOS operating systems and also cover the different problems faced during the installation.

In order to run Rust code in your workstations, we have to install the Rust compiler. We require Unix-based operating systems such as Linux distributions and macOS.

How to do it...

Follow these steps to set up Rust on your system:

Open the Terminal.

Note In macOS, you can open the Terminal by pressing the F4 key, which opens the launchpad and searches for the Terminal. Then, you can select the Terminal option in the display. This is just one possible way of doing it; there are other ways too. In Linux distributions, we can jointly press Ctrl + Alt + T to open the Terminal or search for it in the application search window.

Â

Type the following command to install the Rust compiler and Cargo in your system:

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

You can also try using the following command:

curl -sf https://static.rust-lang.org/rustup.sh | sudo sh

The preceding commands will start the installation, and as it proceeds, the script will require user input. Enter for the default installation, which is the standard way. After this step, different components will be downloaded. If the installation happens without any error, you should be able to see the following screenshot:

Rust is installed now. Great!

Uninstalling Rust Uninstalling Rust is as easy as installing it. Open the Terminal and type the following command: rustup self uninstall

Rust's compiler version If you have reached here, you have got Rust installed on your system, and you can go ahead and verify it. Open up the Terminal and enter the following command, which will give you the version of Rust installed: rustc --version Take a look at the following screenshot: Here, rustc stands for the Rust compiler and --version displays the Rust version we have downloaded. By default, the rustup.sh script downloads the latest stable build. In this book, we are working with the 1.14.0 version. Congrats, if you have reached this step without any error! Rust has been installed successfully.

Advanced installation options A few other commands with the rustup.sh script are as follows. These commands are not necessary for common usage. The following commands are advanced commands that are not usually used by developers at an early stage of Rust development. Install to a particular location: rustup.sh prefix=my/install/dir Save the download for faster reinstallation: rustup.sh save Install nightly: rustup.sh channel=nightly Install nightly archives: rustup.sh --channel=nightly date=2015-04-09 Install the explicit versions: rustup.sh --revision=1.0.0-beta These commands help with the installation of a particular build, unstable releases, and version-controlled component installation.