Skip to main content

Install Rust

Install

Use rustup to install and version control rust. After installing rustup, add $HOME/.cargo/bin to your PATH.

sudo pacman -S rustup

rustup

To update rustc and other programs using rustup, run rustup update.

rustup update

If you want to update rustup itself, you can update it with the package manager of your distribution or run rustup self update.

rustup self update

Uninstall rustup with following command.

rustup self uninstall

cargo

To create new project, run cargo new.

cargo new dir_name --bin

If you don't use version control such as git, add --vcs none.

cargo new dir_name --bin --vcs none

Build is done with cargo build, but if you don't want to make an executable, run cargo check.

cargo build # create executable file
cargo check # don't create executable file

To execute it, use cargo run.

cargo run

If you want to run it in the nightly version of rust, you can do the following.

rustup run nightly cargo run

rustc

rustc is a compiler for rust that can handle small code without using cargo.

rustc main.rs
./main

rustfmt

rustfmt main.rs