Lesson 01-Installing Rust

1 분 소요

한국어(Korean) Page

Rust Installation and Project Management

Installation Guide - Rust Programming Language

This document outlines the necessary steps to install Rust and introduces Cargo, Rust’s build system and package manager.

1. Rust Compiler (rustc)

1.1. Installation

To install the Rust compiler:

  • Windows: Execute the rustup-init.exe installer.
  • Linux/macOS: Run the following command in your terminal:
    curl https://sh.rustup.rs -sSf | sh

The rustc compiler is the core component for compiling Rust code.

1.2. Environment Variable Configuration (Windows)

On Windows, ensure that the following path is added to your system’s environment variables:

    %USERPROFILE%\.cargo\bin

This step enables you to execute Rust binaries from the command line.

2. Cargo: The Rust Build System and Package Manager

Cargo is the primary tool for managing Rust projects. It simplifies tasks such as building code and managing dependencies.

2.1. Verify Cargo Installation

Confirm that Cargo is installed correctly by running:

    cargo --version

This command will display the installed Cargo version.

2.2. Create a New Project

To create a new Rust project, use the following command:

    cargo new hello_cargo

This command generates a new directory named hello_cargo containing the project structure. A Cargo.toml file will be created.

The Cargo.toml file is the manifest file for Rust projects, similar to package.json in Node.js projects. It defines project metadata and dependencies. TOML (Tom’s Obvious, Minimal Language) is the configuration file format used by Cargo.

2.3. Build the Project

Build the project using one of the following methods:

    cargo build (--release)

Or, alternatively:

    rustc main.rs

The cargo build command compiles the project. The --release flag enables production optimizations. You can also compile directly with rustc.

2.4. Run the Executable

Execute the compiled binary using:

    cargo run

Alternatively, run the executable directly:

    ./target/debug/hello_cargo

The compiled executable is located in the /target/debug/ directory.

2.5. Check the Project

To perform a quick check for errors without building an executable, use:

    cargo check

This command performs a faster analysis than cargo build and is useful for quickly identifying potential issues.

Reference

댓글남기기