Skip to content

Rust

Install Rust

We recommend using rustup to install Rust.
The following command will download and run the rustup installation script and guide you through the Rust installation process:

sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Update Rust

After running the previous command, you can update Rust to the latest version using rustup:

sh
rustup update

Cargo

Cargo is Rust's official package manager and build system. It comes bundled with rustup, so if you have installed Rust using rustup, you already have Cargo. It is used to manage Rust projects, dependencies, and build processes.

Create a new cargo project

For a binary, i.e., an executable program:

The following will create a new directory named my_project and initialize a new Cargo project within it:

sh
cargo new my_project

Alternatively, you can initialize a new Cargo project in an existing directory:

sh
mkdir my_project
cd my_project
cargo init

If you are building a library instead of an executable, you can use the --lib flag:

sh
cargo new my_library --lib

or

sh
mkdir my_library
cd my_library
cargo init --lib

INFO

  • cargo new pkg-name creates a new directory.
  • cargo init initializes a new project in the current directory.

Resources