Skip to content

Latest commit

 

History

History
104 lines (82 loc) · 4.49 KB

02. setting_up_rust_environment.md

File metadata and controls

104 lines (82 loc) · 4.49 KB

2. Setting Up Rust Development Environment

To get started with Rust development, you need to set up your development environment. Follow the instructions below based on your operating system:

Linux

  1. Installing Rust:

    • Open a terminal.
    • Run the following command to install Rust using Rustup, the official installer for Rust:
      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    • Follow the prompts to complete the installation process.
  2. Choosing a Text Editor or IDE:

    • Popular choices for Rust development on Linux include Visual Studio Code, Vim, Emacs, and Sublime Text.
    • Install your preferred text editor or IDE using your distribution's package manager or by downloading it from the official website.
  3. Configuring Environment Variables:

    • Rust environment variables are automatically configured during installation. If you encounter any issues, ensure that the following paths are included in your PATH environment variable:
      • $HOME/.cargo/bin
      • /usr/local/cargo/bin (if installed system-wide)
  4. Managing Rust Projects with Cargo:

    • Cargo is the official package manager and build system for Rust.
    • Create a new Rust project by running the following command in your terminal:
      cargo new my_project
    • Navigate to your project directory and start coding!
  5. Testing Your Rust Installation:

    • To verify that Rust and Cargo are installed correctly, run the following commands in your terminal:
      rustc --version
      cargo --version
    • You should see the versions of Rust and Cargo installed on your system.

Windows

  1. Installing Rust:

    • Download the Rustup installer from the official website: rustup.rs.
    • Run the installer and follow the prompts to complete the installation process.
  2. Choosing a Text Editor or IDE:

    • Popular choices for Rust development on Windows include Visual Studio Code, Atom, and Sublime Text.
    • Install your preferred text editor or IDE by downloading it from the official website.
  3. Configuring Environment Variables:

    • Rust environment variables are automatically configured during installation. If you encounter any issues, ensure that the following paths are included in your system's PATH environment variable:
      • %USERPROFILE%\.cargo\bin
      • %USERPROFILE%\AppData\Local\cargo\bin (if installed system-wide)
  4. Managing Rust Projects with Cargo:

    • Follow the same steps as outlined for Linux to create and manage Rust projects using Cargo.
  5. Testing Your Rust Installation:

    • Open a Command Prompt or PowerShell window.
    • Run the following commands to verify that Rust and Cargo are installed correctly:
      rustc --version
      cargo --version
    • You should see the versions of Rust and Cargo installed on your system.

macOS

  1. Installing Rust:

    • Open a terminal.
    • Run the following command to install Rust using Rustup:
      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    • Follow the prompts to complete the installation process.
  2. Choosing a Text Editor or IDE:

    • Popular choices for Rust development on macOS include Visual Studio Code, Atom, and Sublime Text.
    • Install your preferred text editor or IDE by downloading it from the official website or using Homebrew.
  3. Configuring Environment Variables:

    • Rust environment variables are automatically configured during installation. If you encounter any issues, ensure that the following paths are included in your PATH environment variable:
      • $HOME/.cargo/bin
  4. Managing Rust Projects with Cargo:

    • Follow the same steps as outlined for Linux to create and manage Rust projects using Cargo.
  5. Testing Your Rust Installation:

    • Open a terminal.
    • Run the following commands to verify that Rust and Cargo are installed correctly:
      rustc --version
      cargo --version
    • You should see the versions of Rust and Cargo installed on your system.

Additional Suggestions:

For IDE, Visual Studio Code is preferred due to its excellent Rust support. Install the Rust Extension Pack by Swellaby in Visual Studio Code, which includes:

  • Rust Analyser: Provides code analysis, completion, and navigation features.
  • Even Better Toml: Enhances support for TOML files commonly used in Rust projects.
  • crates: Simplifies managing Rust dependencies within Visual Studio Code.