Skip to main content

Installing Rust in your computer

Go to the website and follow the instruction for your OS. On UNIX/Linux:

curl --proto '=https' --tlsv1.2 -sSf | sh

Non interactive install in Ubuntu:

apt update && apt install -y curl && \
curl -sSf | sh -s -- -y
# source $HOME/.cargo/env

Once the program is installed, we can check by printing its version:

rustc --version

For updating:

rustup update

Compiling a simple program:


# if you would like to change the name of the output
rustc -o my_program

# optimize the executable
rustc -O

Executing the binary after compilation:



For larger rust projects (with other package dependencies and with large number of source files), rust package manager cargo can be used. Create a new project:

cargo new my_rust_project

There are two types of crates/ packages: library and binary. By default, cargo will create binary packages, which contains a main program. We can create specific type of package by:

cargo new my_rust_project --bin
cargo new my_rust_project --lib

Alternatively, we can create our project folder manually, and initialize cargo:

mkdir new_rust_project
cd new_rust_project
cargo init
# or
cargo init --lib


cd my_rust_project
cargo run


cargo build

Executable will be placed under: target/debug/.


cargo build --release

You can find optimized binary under: target/release/.

Update cargo dependencies:

cargo update --dry-run
cargo update

# update specific package(s)
cargo update -p rand -p color

cargo update -p rand --precise 0.8.0

Additional tools


rustup component add clippy

Use clippy:

cargo clippy

It is probably faster than compile and run the code.

Rust analyzer:

rustup component add rust-analyzer