Installing Rust from source

1. Introduction

Rust is a relatively new language with focus on fast and secure programming. It has some very neat features:

This article describes how to install the Rust compiler from source. The reason for doing this is that I think for a good future proof installation you should not need to rely on someone else providing binary packages for the compiler. So even in ten years from now, you should still be able to set up the compiler environment for your software and be able to generate a run-able binary.

Good indication that the compiler suite will work in ten years is that the requirements list is small and does not require exotic tools itself.

Also, often I want to try out new languages and compilers without having to mess around with the system. So I prefer a user-only installation into a directory of my choice. A good compiler environment should support that as well.

2. Installation

  1. Download from https://www.rust-lang.org/downloads.html
  2. Get signature from "the archives" (http://static.rust-lang.org/dist/index.html)
  3. Verify signature:
    $ gpg --verify rustc-1.8.0-src.tar.gz.asc
    
  4. Unpack rust-1.8.0-src.tar.gz
  5. Check the README.md for dependencies. Basically you need:
    • g++ 4.7 or clang++ 3.x
    • python 2.7
    • GNU make 3.81 or later
  6. Configure the software:
    $ ./configure --prefix=<your install path>
    
  7. And build it:
    $ make -j4
    
    Get a cup of tea as it will take one to two hours on a 2014 computer.
  8. Install:
    $ make install
    
  9. Done!

3. Test compiler

  1. Prepare PATH for installation path:
    $ export PATH=$PATH:<your install path>/bin
    
  2. Create a file "hello.rs":
    fn main() {
      println!("Hello World!");
    }
    
  3. Compile:
    rustc hello.rs
    
  4. Run:
    ./hello