Setup Rust on macOS
This time, I'll explain how to set up a Rust environment on macOS.
- macOS 15.6.1 (Sequoia)
- Rust 1.89.0
Rust Development Environment Setup
Let's immediately set up the Rust development environment.
Installing the rustup-init Command
In Rust, we mainly use commands like cargo, rustc, rustup, and rustdoc.
By installing the rustup-init command, all these commands become available for use together.
Installing the rustup-init Command
Install using Homebrew.
brew install rustup-init
Running the rustup-init Command
rustup-init
The following options will be displayed, but basically selecting option 1, standard installation, is fine.
1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>
Verifying Commands
Restart your shell and verify that each command has been installed correctly.
cargo --version
rustc --version
rustup --version
rustdoc --version
If each version is displayed, they have been installed correctly!
Basic Usage of Each Command
Now that each command has been installed, let me explain their basic usage.
cargo Command
The cargo command is used for Rust project management, compilation, testing, building, and more.
It's similar to Node.js's npm command.
# Create a project
cargo new <project-name>
# Create project (in current directory)
cargo init
# Build
cargo build
# Run
cargo run
# Test
cargo test
# Install packages
cargo install
# Uninstall packages
cargo uninstall
rustc Command
The rustc command is used for compiling Rust code.
While the cargo command is used in most cases, you can also compile directly with the rustc command.
# Compile
rustc <file-name>
rustup Command
The rustup command is used for Rust version management.
It's similar to Node.js's nodebrew or nvm commands.
# Update version
rustup update
# Update stable version
rustup update stable
# Update latest version
rustup update nightly
rustdoc Command
The rustdoc command is used for generating Rust documentation.
# Generate documentation
rustdoc <file-name>
Creating a Rust Project
Let's actually create a Rust project.
cargo new hello-rust
If you want to create a project within an already created directory, use cargo init in that directory.
Next, open src/main.rs and write the following code:
fn main() {
println!("Hello, World!");
}
Now let's run it:
cargo run
If "Hello, World!" is displayed, you're all set!
Summary
I've explained how to set up a Rust environment.
By using the rustup-init command, various commands become immediately available, making environment setup smooth.
Let's dive into the exciting world of Rust!