Getting Started - Rust Programming Language
Getting Started - Rust Programming Language
Rust
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.
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".
If you’re a Windows Subsystem for Linux user run the following in your terminal, then follow the on-screen instructions to install
Rust.
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
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:
To test that you have Rust and Cargo installed, you can run this in your terminal of choice:
cargo --version
Other tools
VS CODE
SUBLIME TEXT
ATOM
RUSTROVER
ECLIPSE
VIM
EMACS
GEANY
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
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.
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
$ 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 our Cargo.toml file we’ll add this information (that we got from the crate page):
[dependencies]
ferris-says = "0.3.1"
cargo build
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.
Now let’s write a small application with our new dependency. In our main.rs , add the following code:
fn main() {
let stdout = stdout();
let message = String::from("Hello fellow Rustaceans!");
let width = message.chars().count();
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!
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!
Get help!
Documentation
English (en-US)
Code of Conduct
Licenses
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
https://www.rust-lang.org/learn/get-started 6/6