เชี่ยวชาญการใช้ apt install บน Ubuntu: คู่มือครบวงจรสำหรับการจัดการแพ็กเกจ การอัปเกรด และการแก้ไขปัญหา

answer.## 1. บทนำ

When using Ubuntu, the apt install command is essential for installing and managing software. With this command, you can easily install applications from package repositories.

เมื่อใช้ Ubuntu คำสั่ง apt install มีความสำคัญสำหรับการติดตั้งและจัดการซอฟต์แวร์ ด้วยคำสั่งนี้คุณสามารถติดตั้งแอปพลิเคชันจากคลังแพ็กเกจได้อย่างง่ายดาย

This article provides a complete guide—from basics to advanced usage, troubleshooting, and frequently asked questions—so that beginners and intermediate users alike can smoothly manage packages in Ubuntu.

บทความนี้ให้คำแนะนำอย่างครบถ้วน ตั้งแต่พื้นฐานจนถึงการใช้งานขั้นสูง การแก้ไขปัญหา และคำถามที่พบบ่อย เพื่อให้ผู้เริ่มต้นและผู้ใช้ระดับกลางสามารถจัดการแพ็กเกจใน Ubuntu ได้อย่างราบรื่น

2. คำสั่ง apt คืออะไร?

apt คืออะไร?

apt (Advanced Package Tool) is a command-line utility used for package management on Ubuntu and Debian-based Linux distributions. Using APT allows you to perform the following actions:

apt (Advanced Package Tool) เป็นยูทิลิตี้บรรทัดคำสั่งที่ใช้สำหรับการจัดการแพ็กเกจบน Ubuntu และดิสทริบิวชัน Linux ที่อิง Debian การใช้ APT ทำให้คุณสามารถทำการต่อไปนี้ได้:

  • Install software
  • ติดตั้งซอฟต์แวร์
  • Update software
  • อัปเดตซอฟต์แวร์
  • Remove unnecessary software
  • ลบซอฟต์แวร์ที่ไม่จำเป็น
  • Resolve dependency issues
  • แก้ไขปัญหาการพึ่งพา

Package management on Ubuntu is primarily carried out using the apt command.

การจัดการแพ็กเกจบน Ubuntu ส่วนใหญ่ทำโดยใช้คำสั่ง apt

ความแตกต่างระหว่าง apt และ apt-get

Previously, apt-get was the standard tool, but apt is now recommended. Their differences are summarized in the following table:

ก่อนหน้านี้ apt-get เป็นเครื่องมือมาตรฐาน แต่ตอนนี้แนะนำให้ใช้ apt ความแตกต่างของพวกมันสรุปไว้ในตารางต่อไปนี้:

CommandCharacteristics
aptMore user-friendly with improved progress indicators
apt-getLegacy command offering more granular control (advanced users only)

Use apt for basic package management, and switch to apt-get when performing specific advanced operations.

ใช้ apt สำหรับการจัดการแพ็กเกจพื้นฐาน และเปลี่ยนไปใช้ apt-get เมื่อทำการดำเนินการขั้นสูงเฉพาะ

3. การดำเนินการพื้นฐานของ apt

อัปเดตรายการแพ็กเกจ

Before installing software, update the package list to ensure the latest information is available.

ก่อนติดตั้งซอฟต์แวร์ ควรอัปเดตรายการแพ็กเกจเพื่อให้แน่ใจว่ามีข้อมูลล่าสุด

sudo apt update

This command refreshes the list of available software for the Ubuntu package manager.
Tip: If you install software with outdated package information, the latest versions may not be retrieved—so run this command regularly.

คำสั่งนี้รีเฟรชรายการซอฟต์แวร์ที่พร้อมใช้งานสำหรับตัวจัดการแพ็กเกจของ Ubuntu
เคล็ดลับ: หากคุณติดตั้งซอฟต์แวร์ด้วยข้อมูลแพ็กเกจที่ล้าสมัย เวอร์ชันล่าสุดอาจไม่ถูกดึงมา—ดังนั้นควรรันคำสั่งนี้เป็นประจำ

ติดตั้งแพ็กเกจ

Use the following command to install new software:

ใช้คำสั่งต่อไปนี้เพื่อติดตั้งซอฟต์แวร์ใหม่:

sudo apt install package-name

For example, to install curl:

ตัวอย่าง การติดตั้ง curl:

sudo apt install curl

During installation, a message such as “This package requires XX MB. Continue?” will appear. Press “Y” to proceed.

ระหว่างการติดตั้ง จะมีข้อความเช่น “แพ็กเกจนี้ต้องการ XX MB. ดำเนินการต่อ?” ป้อน “Y” เพื่อดำเนินการต่อ

ลบแพ็กเกจ

To remove software you no longer need, use the following command:

เพื่อลบซอฟต์แวร์ที่คุณไม่ต้องการใช้ต่อ ให้ใช้คำสั่งต่อไปนี้:

sudo apt remove package-name

For example, to remove curl:

ตัวอย่าง การลบ curl:

sudo apt remove curl

To completely delete a package along with its configuration files, use:

เพื่อลบแพ็กเกจอย่างสมบูรณ์พร้อมไฟล์การกำหนดค่า ให้ใช้:

sudo apt purge package-name

4. การใช้งาน apt ขั้นสูง

อัปเกรดแพ็กเกจเฉพาะ

You can upgrade only a specific package without updating the entire system:

คุณสามารถอัปเกรดเฉพาะแพ็กเกจหนึ่งโดยไม่ต้องอัปเดตระบบทั้งหมด:

sudo apt install --only-upgrade package-name

Example – Upgrade vim:

ตัวอย่าง – อัปเกรด vim:

sudo apt install --only-upgrade vim

ลบแพ็กเกจที่ไม่จำเป็นโดยอัตโนมัติ

To remove unused packages installed as dependencies, run:

เพื่อลบแพ็กเกจที่ไม่ได้ใช้ซึ่งติดตั้งเป็นการพึ่งพา ให้รัน:

sudo apt autoremove

ดูรายละเอียดแพ็กเกจ

Check detailed information about a package using:

ตรวจสอบข้อมูลรายละเอียดของแพ็กเกจโดยใช้:

apt show package-name

Example – View details for git:

ตัวอย่าง – ดูรายละเอียดของ git:

apt show git

แสดงรายการแพ็กเกจที่ติดตั้ง

To display all installed packages, run:

เพื่อแสดงแพ็กเกจที่ติดตั้งทั้งหมด ให้รัน:

apt list --installed

5. การแก้ไขปัญหา

ปัญหาการพึ่งพา

If you encounter dependency problems when installing a package, try the following command:

หากคุณเจอปัญหาการพึ่งพาเมื่อทำการติดตั้งแพ็กเกจ ให้ลองใช้คำสั่งต่อไปนี้:

sudo apt install -f

This command fixes broken dependencies.

คำสั่งนี้จะแก้ไขการพึ่งพาที่เสียหาย

เพิ่มหรือเอารีโพซิทอรีออก

To install software that requires a specific repository, add it using:

เพื่อติดตั้งซอฟต์แวร์ที่ต้องการรีโพซิทอรีเฉพาะ ให้เพิ่มโดยใช้:

sudo add-apt-repository ppa:repository-name
sudo apt update

To remove a repository you no longer need:

เพื่อลบรีโพซิทอรีที่คุณไม่ต้องการอีกต่อไป:

sudo add-apt-repository --remove ppa:repository-name
sudo apt update

6. คำถามที่พบบ่อย

ควรใช้ apt หรือ apt-get?

On modern Ubuntu systems, apt is recommended.

บนระบบ Ubuntu รุ่นใหม่ แนะนำให้ใช้ apt

ความแตกต่างระหว่าง apt update กับ apt upgrade

  • apt update → Updates the package list
  • apt update → อัปเดตรายการแพ็กเกจ
  • apt upgrade → Upgrades installed packages to the latest versions
  • apt upgrade → อัปเกรดแพ็กเกจที่ติดตั้งเป็นเวอร์ชันล่าสุด

วิธีอัปเกรดเฉพาะแพ็กเกจเดียว

Use the following command:

ใช้คำสั่งต่อไปนี้:

sudo apt install --only-upgrade package-name

ตรวจสอบตำแหน่งที่ติดตั้งแพ็กเกจ

You can verify the installation location with:

คุณสามารถตรวจสอบตำแหน่งการติดตั้งด้วย:

dpkg -L package-name

ตรวจสอบแหล่งที่มาของรีโพซิทอรีของแพ็กเกจ

apt-cache policy package-name

7. บทสรุป

บทความนี้ได้อธิบายทุกอย่างตั้งแต่การใช้งานพื้นฐานของ apt install บน Ubuntu ไปจนถึงเทคนิคขั้นสูงและการแก้ไขปัญหา
โดยการเชี่ยวชาญคำสั่ง apt คุณสามารถจัดการสภาพแวดล้อม Ubuntu ของคุณได้อย่างมีประสิทธิภาพมากขึ้น

📌 ลิงก์อ้างอิง:

ศึกษาต่อเกี่ยวกับ Ubuntu เพิ่มเติมเพื่อให้บรรลุการดูแลระบบที่มีประสิทธิภาพและเหมาะสม!