Appearance
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 | shUpdate Rust
After running the previous command, you can update Rust to the latest version using rustup:
sh
rustup updateCargo
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_projectAlternatively, you can initialize a new Cargo project in an existing directory:
sh
mkdir my_project
cd my_project
cargo initIf you are building a library instead of an executable, you can use the --lib flag:
sh
cargo new my_library --libor
sh
mkdir my_library
cd my_library
cargo init --libINFO
cargo new pkg-namecreates a new directory.cargo initinitializes a new project in the current directory.