Setting up Rust development environment on Linux

I use a Debian based Linux distro but the steps given below should work for a variety of Linux distros.

Installing Rust

There are many ways to go about installing Rust on Linux.

First, you could download the archive from the Rust website and add the bin folder to your PATH.

Second, you can use the rustup shell script to install the latest stable, beta or nightly version:


        $ curl -sSf https://static.rust-lang.org/rustup.sh | sh
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=beta
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly

However, my preffered way of installing Rust is to make use of the Rust Version Manager. The reason being: Rust, despite being well engineered, is a relatively new technology. In the absence of a long term stable (LTS) version (and perhaps even with an LTS), it's very likely I end up with different projects each requiring versions of Rust. This is based on my experience with Java, Scala, Python and even Node. With `rsvm` I get a tool to easily and efficiently manage and use different Rust versions.


        # installing rust version manager
        $ curl -L https://raw.github.com/sdepold/rsvm/master/install.sh | sh

        # test rsvm
        $ rsvm

        Rust Version Manager
        ====================

        Usage:

          rsvm help | --help | -h       Show this message.
          rsvm install         Download and install a .
                                         could be for example "0.12.0".
          rsvm uninstall       Uninstall a .
          rsvm use             Activate  for now and the future.
          rsvm ls | list                List all installed versions of rust.
          rsvm ls-remote                List remote versions available for install.
          rsvm ls-channel               Print a channel version available for install.

        # install rust
        $ rsvm install 1.6.0

        # test rustc
        $ rustc --version
        rustc 1.6.0 (c30b771ad 2016-01-19)
    

Editor Wars

This is a tricky one. Everybody has a favorite editor / IDE but "which one is the best?" is a never-ending discussion. I don't wish to go there.

Let me just share what I use: Sublime Text 3 with the Rust plugin.

In additional to Sublime Text, Rust plugins and addons can be found for a number of IDEs and editors including IntelliJ IDEA, Eclipse, Visual Studio, Atom, Vim, Emacs etc.

Hello World


        # generate hello world with cargo
        $ cargo new helloworld --bin

        # hello world
        $ cd helloworld
        $ tree
        .
        ├── Cargo.toml
        └── src
            └── main.rs

        $ more src/main.rs
        fn main() {
            println!("Hello, world!");
        }

        $ cargo run
        Compiling helloworld v0.1.0 (file:///tmp/rust-tmp/helloworld)
        Running `target/debug/helloworld`
        Hello, world!
    

There you go, you have a perfectly working Rust development environment. Time to start writing some code!