Getting Started With Rust

When I first started learning Rust, it was important for me to learn how to set up my environment properly. That effort resulted in a blog post that sparked the idea for this book. I discovered there are many similarities between the Ruby and Rust ecosystems. Let’s get started.

With Ruby, you can install the runtime on your machine and begin. Many community members will use a version manager like rbenv. Rust doesn’t have an equivalent in that you switch between different versions by semantic version. There are toolchains, which can be thought of as versions, but I’ll get into those in a bit.

With Rust, you can be confident that developing on the latest stable version is the way to go. Before we get too ahead of ourselves, let’s install Rust.

The recommended way to install Rust locally is via rustup. Essentially, you are running a shell script that installs an executable–the Rust compiler.

  • Note: we didn’t simply say use homebrew or other package manager

Rustup gets us the latest “version” of the Rust compiler. Notice “version” is in quotes. Officially, Rust calls these toolchains. A toolchain is made up of a release channel and the compilation targets. If you are on a Mac, your compilation target is MacOS. There are three release channels. Nightly, beta, and stable. Nightly is the state of the main branch. It is work in progress. Possibly incomplete. Bleeding edge. Beta can be thought of as complete and ready for the community to test. Stable is an official release blessed by the community.

If you are developing a library to share with the community, you may want to test it against beta for example. You may want to have your tests run against all three release channels. But when in development, it probably makes most sense to use stable. You can switch between the release channels using: rustup default nightly for example. The equivalent in Ruby would be using your version manager to switch to a pre-release version of Ruby. As of this writing, a modern example would be Ruby 3.4.0-preview2. That would be similar to switching to the beta release channel of Rust.

You can see what version of Rust you have installed by asking the Rust compiler: rustc --version.

Side note: like using a .ruby-version file in your project, you can use a rust-toolchain file in your Rust project to specify the release channel you want to use.

Now that we have Rust installed and understand we’re going to use the “stable version”, let’s compare some of the ecosystem to Ruby.