Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

การติดตั้ง Rust

ติดตั้งด้วย rustup

rustup เป็นเครื่องมืออย่างเป็นทางการสำหรับติดตั้งและจัดการ Rust

🛠️ Rust Toolchain Overview

+-------------------------------------------------------------------+
|                  Rust Development Toolchain                       |
+-------------------------------------------------------------------+
|                                                                   |
|  rustup (Toolchain Manager)                                       |
|  +-- rustc (Compiler)      <-- compile .rs to executable          |
|  +-- cargo (Build Tool)    <-- manage project + dependencies      |
|  +-- rustfmt (Formatter)   <-- auto format code                   |
|  +-- clippy (Linter)       <-- best practices suggestions         |
|  +-- rust-docs (Docs)      <-- offline documentation              |
|                                                                   |
|  IDE Setup (Recommended)                                          |
|  +-------------------------------------------------------+        |
|  |  VS Code + rust-analyzer extension                    |        |
|  |  * Auto-complete                                      |        |
|  |  * Error highlighting                                 |        |
|  |  * Go to definition                                   |        |
|  |  * Inline type hints                                  |        |
|  +-------------------------------------------------------+        |
|                                                                   |
+-------------------------------------------------------------------+

สำหรับ Windows

  1. ดาวน์โหลด rustup จาก https://rustup.rs
  2. เปิดไฟล์ที่ดาวน์โหลดมาและทำตามขั้นตอน
  3. อาจต้องติดตั้ง Visual Studio Build Tools ด้วย

สำหรับ macOS และ Linux

เปิด Terminal แล้วพิมพ์คำสั่ง:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

ทำตามขั้นตอนที่แสดงบนหน้าจอ


ตรวจสอบการติดตั้ง

หลังติดตั้งแล้ว ปิดและเปิด Terminal ใหม่ แล้วพิมพ์:

rustc --version

ถ้าติดตั้งสำเร็จ จะเห็นข้อความคล้ายๆ นี้:

rustc 1.83.0 (90b35a623 2024-11-26)

ลองตรวจสอบ Cargo ด้วย:

cargo --version

จะได้:

cargo 1.83.0 (5ffbef321 2024-10-29)

อัปเดต Rust

Rust ออกเวอร์ชันใหม่ทุก 6 สัปดาห์ อัปเดตได้ด้วย:

rustup update

เลือก IDE / Text Editor

แนะนำให้ใช้ VS Code พร้อม extension:

  1. rust-analyzer - สำคัญมาก!
  2. Even Better TOML
  3. Error Lens

หรือจะใช้ RustRover ซึ่งเป็น IDE เฉพาะสำหรับ Rust จาก JetBrains ก็ได้


สรุป

✅ ติดตั้ง Rust ด้วย rustup
✅ ตรวจสอบด้วย rustc --version
✅ ติดตั้ง VS Code + rust-analyzer

👉 ต่อไป: Hello World