This chapter guides you through setting up your Rust development environment and writing your first program. By the end, you'll have a fully configured workspace and understand the basics of Cargo, Rust's build system and package manager.
Rust is installed through rustup, the official Rust toolchain installer. It manages Rust versions and associated tools, making it easy to keep your installation up to date.
Open your terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This command downloads and runs the rustup installer. Follow the on-screen prompts (usually pressing Enter for default options is fine).
The installer will add the following to your shell configuration:
source "$HOME/.cargo/env"
source ~/.cargo/env
Visit rustup.rs and download rustup-init.exe
Rust requires the Microsoft C++ Build Tools. The installer will prompt you to install them if needed.
After installation, verify everything works:
# Check Rust compiler version rustc --version # Example output: rustc 1.75.0 (82e1608df 2023-12-21) # Check Cargo version cargo --version # Example output: cargo 1.75.0 (1d8b05cdd 2023-11-20) # Check rustup version rustup --version # Example output: rustup 1.26.0 (5af9b9484 2023-04-05)
rustup installs these essential components:
rustc - The Rust compilercargo - Build system and package managerrustup - Toolchain managerrustfmt - Code formatterclippy - Linterrust-docs - Local documentationRust releases a new stable version every six weeks. Keep your installation current:
# Update Rust to the latest version rustup update # Show installed toolchains rustup show # Install a specific version rustup install 1.70.0 # Switch default toolchain rustup default stable # Install nightly (for experimental features) rustup install nightly rustup run nightly cargo build
Use stable for production code. The nightly channel has experimental features that may change. Some tools (like rocket web framework) may require nightly.
A good IDE makes Rust development much more productive. We recommend Visual Studio Code with the rust-analyzer extension.
Download from code.visualstudio.com
Search for "rust-analyzer" in the Extensions panel (Ctrl+Shift+X) and install it.
| Feature | Description |
|---|---|
| Code completion | Smart suggestions as you type |
| Go to definition | Jump to function/type definitions (F12) |
| Inline errors | See compiler errors without building |
| Inlay hints | Show types and parameter names inline |
| Rename refactoring | Safely rename across project |
| Code actions | Quick fixes and code generation |
Let's create and run your first Rust program using Cargo.
# Create a new project called hello_rust cargo new hello_rust # Navigate into the project cd hello_rust
Cargo creates this project structure:
Open Cargo.toml - this is your project's manifest:
[package] name = "hello_rust" version = "0.1.0" edition = "2021" # See more keys and their definitions at # https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] # Your external dependencies go here
[package] - Project metadata (name, version, edition)edition - Rust edition (2015, 2018, 2021) - use latest[dependencies] - External crates your project uses[dev-dependencies] - Dependencies only for tests/examples[build-dependencies] - Dependencies for build scriptsOpen src/main.rs:
fn main() {
println!("Hello, world!");
}
Let's break this down:
| Code | Explanation |
|---|---|
fn |
Keyword to define a function |
main() |
The entry point - every Rust program starts here |
{ } |
Function body enclosed in curly braces |
println! |
A macro (note the !) that prints to console |
"Hello, world!" |
A string literal |
; |
Statements end with semicolons |
# Build and run
cargo run
# Output:
Compiling hello_rust v0.1.0 (/path/to/hello_rust)
Finished dev [unoptimized + debuginfo] target(s) in 0.42s
Running `target/debug/hello_rust`
Hello, world!
You've just written and run your first Rust program!
Cargo is your constant companion in Rust development. Here are the essential commands:
| Command | What It Does |
|---|---|
cargo new <name> |
Create a new project |
cargo build |
Compile the project |
cargo run |
Build and run |
cargo check |
Check for errors without building (faster) |
cargo test |
Run tests |
cargo fmt |
Format code |
cargo clippy |
Run linter for code improvements |
cargo doc --open |
Generate and open documentation |
cargo build --release |
Build optimized release version |
cargo add <crate> |
Add a dependency |
# Debug build (fast compilation, slow execution, with debug symbols) cargo build # Binary: target/debug/hello_rust # Release build (slow compilation, fast execution, optimized) cargo build --release # Binary: target/release/hello_rust
Use cargo run during development for fast iteration. Use cargo build --release for performance testing and deployment. The performance difference can be 10-100x!
Rust's package ecosystem lives on crates.io. Let's add a dependency:
# Add the rand crate cargo add rand
This updates your Cargo.toml:
[dependencies] rand = "0.8.5"
Now use it in your code:
use rand::Rng;
fn main() {
let secret_number = rand::thread_rng().gen_range(1..=100);
println!("Secret number: {}", secret_number);
}
| Syntax | Meaning |
|---|---|
"0.8.5" |
Compatible with 0.8.5+ but less than 0.9.0 |
"^0.8.5" |
Same as above (caret is default) |
"~0.8.5" |
Patch updates only (0.8.5 - 0.8.x) |
"=0.8.5" |
Exactly this version |
"*" |
Any version (not recommended) |
As your project grows, organize it properly:
# Create a library project cargo new my_library --lib # Create a binary project (default) cargo new my_app
main.rs, produces an executablelib.rs, produces a library for others to userustup to install and manage Rust toolchainsCargo.toml for configuration, src/ for codecargo addrustup and why is it preferable to installing Rust from package managers?cargo build and cargo check? When would you use each?Cargo.toml file. What sections does it contain?! in println! indicate?In the next chapter, you'll learn Rust's most important concept—ownership. This is what makes Rust unique and enables memory safety without garbage collection:
Korea operates a comprehensive standards governance system through inter-ministerial cooperation. National Standards Council (under Prime Minister's Office, per Framework Act on National Standards Article 5) coordinates KATS (Korean Agency for Technology and Standards), MFDS (Ministry of Food and Drug Safety), MOTIE (Ministry of Trade, Industry and Energy), MSIT (Ministry of Science and ICT), MOIS (Ministry of the Interior and Safety), MOE (Ministry of Environment), MOHW (Ministry of Health and Welfare), MND (Ministry of National Defense), MCST (Ministry of Culture, Sports and Tourism), MOFA (Ministry of Foreign Affairs), MOJ (Ministry of Justice), and FSC (Financial Services Commission). Accreditation and Testing: KOLAS (Korea Laboratory Accreditation Scheme) accredits 800+ testing laboratories. KAS (Korea Accreditation System) accredits 50+ certification bodies. KTC (Korea Testing Certification), KTR (Korea Testing & Research Institute), KTL (Korea Testing Laboratory), and KCL (Korea Conformity Laboratories) provide conformance testing. Telecom and Cyber: KCC (Korea Communications Commission), KCA (Korea Communications Agency), TTA (Telecommunications Technology Association), IITP (Institute for Information & Communications Technology Planning & Evaluation), NIPA (National IT Industry Promotion Agency), KISA (Korea Internet & Security Agency), KCMVP (Korea Cryptographic Module Validation Program), NIS (National Intelligence Service), NSR (National Security Research Institute), and NCSC (National Cyber Security Center). National R&D Centers: KIST, ETRI, KAIST, Seoul National University, Yonsei University, Korea University, POSTECH, UNIST, GIST, DGIST, KISTI, KIER, KIMM, KRICT, KFRI, KRIBB. International Standards Cooperation: ISO TC/SC Korean secretariats, IEC TC/SC Korean secretariats, ITU-T Study Group Korean chairs, 3GPP RAN/SA Korean chairs, IEEE 802 Korean chairs, W3C Korea office, OASIS Korea office, IETF Korea cooperation, OECD CSTP, UN ESCAP, APEC SCSC Korean cooperation. Korean Industrial Standards (KS) Catalog: KS X (Information) 25,000+, KS A (Basic) 15,000+, KS B (Machinery) 25,000+, KS C (Electrical) 18,000+, KS D (Metallurgy) 12,000+, KS E (Mining) 5,000+, KS F (Construction) 18,000+, KS H (Food) 8,000+, KS I (Environment) 5,000+, KS J (Biology) 3,000+, KS K (Textile) 15,000+, KS L (Ceramics) 7,000+, KS M (Chemistry) 12,000+, KS P (Medical) 5,000+, KS Q (Quality Mgmt) 4,000+, KS R (Transport) 12,000+, KS S (Service) 3,000+, KS T (Packaging) 4,000+, KS V (Shipbuilding) 5,000+, KS W (Aerospace) 3,000+ — totaling 220,000+ Korean Industrial Standards. Key Acts: Personal Information Protection Act (Act 19234, effective Sept 15, 2024), Electronic Government Act, Electronic Signature Act, Act on Promotion of Information and Communications Network Utilization and Information Protection, Information and Communications Infrastructure Protection Act, Data Industry Act, Public Data Act, AI Framework Act (Act 20212, effective July 2026), Industrial Technology Innovation Promotion Act, Framework Act on Science and Technology — 70+ Korean standardization-related laws.
Korea operates digital transformation through a comprehensive governance system. Digital Government: Digital Platform Government Committee (established September 2022, under the President)·Ministry of the Interior and Safety Digital Government Bureau·e-Government Support Center·Gov.kr·National Citizen Service·KDIS (Korea Digital Information Society)·NIA (National Information Society Agency)·MOIS (Ministry of the Interior and Safety). K-DNS Infrastructure: Korea Internet & Security Agency (KISA) Korea Internet Center·KISA DNS Root Server·KRNIC (Korea Network Information Center)·BGP Korea·National Cyber Security Center (NCSC)·KCC (Korea Communications Commission)·MSIT (Ministry of Science and ICT)·NIA·NIPA. Korean Cloud Infrastructure: KT Cloud·NAVER Cloud (NCloud)·Samsung SDS Cloud·LG U+ Cloud·NHN Cloud·Kakao Enterprise Cloud·SK Telecom Cloud·KISA Cloud Security Assurance Program (CSAP)·KCMVP-validated cloud·ISMS-P (Information Security & Personal Information Management System). Korean Security Certifications: KISA ISMS-P certification·KCMVP (Korean Cryptographic Module Validation Program)·NIS (National Intelligence Service) "National Cryptographic Technology Operation Standards"·NCSC "National Cyber Security Strategy 2024-2028"·CC (Common Criteria) Korean evaluation bodies·EAL4·EAL5·KS X ISO/IEC 15408·19790·24759 Korean Profile. Korean Data Standards: NIA AI Hub·National Data Standardization Committee·Statistics Korea (KOSTAT)·MyData 4 Designated Combination Specialists (Samsung SDS, KICI, KOSTAT, KFTC)·National Institute of Korean Language·National Law Information Center·National Spatial Information Platform·National Spatial Data Center·Korean Spatial Information Standards. Finance and Fintech Standards: FSC (Financial Services Commission)·FSS (Financial Supervisory Service)·FIU (Financial Intelligence Unit)·BOK (Bank of Korea)·FSEC (Financial Security Institute)·KFTC (Korea Financial Telecommunications)·KSD (Korea Securities Depository)·KRX (Korea Exchange) 8-agency cooperation. 5G/6G Communications Infrastructure: 5G subscribers 35 million (2024)·5G base stations 350,000·6G commercialization target 2028·5G dedicated networks 16 operators·6G Acceleration Council (MSIT, 2024). K-Content: KOCCA (Korea Creative Content Agency)·MCST (Ministry of Culture, Sports and Tourism)·KCA (Korea Communications Agency)·Korea Culture Information Service Agency·Korean Film Archive·Korea Publishing Industry Promotion Agency. Data 3 Acts (Personal Information Protection Act·Credit Information Act·Telecommunications Network Act, 2020 enforcement)·Data Industry Act (2021)·Public Data Act (2013)·AI Framework Act (2026)·Digital Platform Government Framework Act (2024 proposed) — Korea digital transformation core legislation.