Install Rust
Install
Use rustup to install and version control rust.
After installing rustup, add $HOME/.cargo/bin to your PATH.
- Arch
- Otherwise
sudo pacman -S rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
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.
- Executable
- Library
cargo new dir_name --bin
cargo new dir_name --lib
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