05.10.
23 17:55 Getting started - Rust Programming Language
Rust
Install Learn Playground Tools Governance Community Blog
English (en-US)
Getting started
Quickly set up a Rust development environment and write a
small app!
Installing Rust
You can try Rust online in the Rust Playground without installing anything on your computer.
TRY RUST WITHOUT INSTALLING
Rustup: the Rust installer and version management tool
The primary way that folks install Rust is through a tool called Rustup, which is a Rust installer and version management tool.
It looks like you’re running Windows. To start using Rust, download the installer, then run the program and follow the onscreen
instructions. You may need to install the Visual Studio C++ Build tools when prompted to do so. If you are not on Windows see
"Other Installation Methods".
DOWNLOAD RUSTUP-INIT.EXE (32-BIT)
DOWNLOAD RUSTUP-INIT.EXE (64-BIT)
Windows Subsystem for Linux
If you’re a Windows Subsystem for Linux user run the following in your terminal, then follow the on-screen instructions to install
Rust.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Is Rust up to date?
Rust updates very frequently. If you have installed Rustup some time ago, chances are your Rust version is out of date. Get the
latest version of Rust by running rustup update .
https://www.rust-lang.org/learn/get-started 1/6
05.10.23 17:55 Getting started - Rust Programming Language
LEARN MORE ABOUT INSTALLATION
Cargo: the Rust build tool and package manager
When you install Rustup you’ll also get the latest stable version of the Rust build tool and package manager, also known as
Cargo. Cargo does lots of things:
build your project with cargo build
run your project with cargo run
test your project with cargo test
build documentation for your project with cargo doc
publish a library to crates.io with cargo publish
To test that you have Rust and Cargo installed, you can run this in your terminal of choice:
cargo --version
READ THE CARGO BOOK
Other tools
Rust support is available in many editors:
VS CODE
SUBLIME TEXT
ATOM
RUSTROVER
ECLIPSE
VIM
EMACS
GEANY
Generating a new project
Let’s write a small application with our new Rust development environment. To start, we’ll use Cargo to make a new project for
us. In your terminal of choice run:
https://www.rust-lang.org/learn/get-started 2/6
05.10.23 17:55 Getting started - Rust Programming Language
cargo new hello-rust
This will generate a new directory called hello-rust with the following files:
hello-rust
|- Cargo.toml
|- src
|- main.rs
Cargo.toml is the manifest file for Rust. It’s where you keep metadata for your project, as well as dependencies.
src/main.rs is where we’ll write our application code.
cargo new generates a "Hello, world!" project for us! We can run this program by moving into the new directory that we made
and running this in our terminal:
cargo run
You should see this in your terminal:
$ cargo run
Compiling hello-rust v0.1.0 (/Users/ag_dubs/rust/hello-rust)
Finished dev [unoptimized + debuginfo] target(s) in 1.34s
Running `target/debug/hello-rust`
Hello, world!
Adding dependencies
Let’s add a dependency to our application. You can find all sorts of libraries on crates.io, the package registry for Rust. In Rust,
we often refer to packages as “crates.”
In this project, we’ll use a crate called ferris-says .
In our Cargo.toml file we’ll add this information (that we got from the crate page):
[dependencies]
ferris-says = "0.3.1"
We can also do this by running cargo add ferris-says .
Now we can run:
cargo build
...and Cargo will install our dependency for us.
https://www.rust-lang.org/learn/get-started 3/6
05.10.23 17:55 Getting started - Rust Programming Language
You’ll see that running this command created a new file for us, Cargo.lock . This file is a log of the exact versions of the
dependencies we are using locally.
To use this dependency, we can open main.rs , remove everything that’s in there (it’s just another example), and add this line
to it:
use ferris_says::say;
This line means that we can now use the say function that the ferris-says crate exports for us.
A small Rust application
Now let’s write a small application with our new dependency. In our main.rs , add the following code:
use ferris_says::say; // from the previous step
use std::io::{stdout, BufWriter};
fn main() {
let stdout = stdout();
let message = String::from("Hello fellow Rustaceans!");
let width = message.chars().count();
let mut writer = BufWriter::new(stdout.lock());
say(&message, width, &mut writer).unwrap();
}
Once we save that, we can run our application by typing:
cargo run
Assuming everything went well, you should see your application print this to the screen:
__________________________
< Hello fellow Rustaceans! >
--------------------------
\
\
_~^~^~_
\) / o o \ (/
'_ - _'
/ '-----' \
Learn more!
https://www.rust-lang.org/learn/get-started 4/6
05.10.23 17:55 Getting started - Rust Programming Language
You’re a Rustacean now! Welcome! We’re so glad to have you. When you’re ready, hop over to our Learn page, where you can find
lots of books that will help you to continue on your Rust adventure.
LEARN MORE!
Who’s this crab, Ferris?
Ferris is the unofficial mascot of the Rust Community. Many Rust programmers call themselves “Rustaceans,” a play on the word
“crustacean.” We refer to Ferris with any pronouns “she,” “he,” “they,” “it,” etc.
Ferris is a name playing off of the adjective, “ferrous,” meaning of or pertaining to iron. Since Rust often forms on iron, it
seemed like a fun origin for our mascot’s name!
You can find more images of Ferris on rustacean.net.
Get help!
Documentation
Rust Forge (Contributor Documentation)
Ask a Question on the Users Forum
English (en-US)
Terms and policies
Code of Conduct
Licenses
Logo Policy and Media Guide
Security Disclosures
Privacy Notice
All Policies
Social
https://www.rust-lang.org/learn/get-started 5/6
05.10.23 17:55 Getting started - Rust Programming Language
Maintained by the Rust Team. See a bug? File an issue!
Looking for the previous website?
https://www.rust-lang.org/learn/get-started 6/6