# OPKG Package Manager

OPKG 是 OpenWRT 上的套件管理工具，其功用就像是 Linux 系統上的 apt-get/yum 一樣，可以藉由一伺服器，透過網際網路提供使用者更新/安裝在 OpenWRT 上的軟體套件，同時，在本地端， OPKG 也可以提供套件的管理，列出安裝的套件，提供一個更易於管理的作業系統與跨裝置的開發環境。

OPKG 主要可以分成以下 5 個功能:

* opkg update (向套件伺服器) 更新可以安裝的套件列表&#x20;
* opkg upgrade 對已安裝的套間更新版本
* opkg list 列出所有套件&#x20;
* opkg install 安裝指定的套件&#x20;
* opkg remove 解除安裝指定的套件

```
# opkg
opkg must have one sub-command argument
usage: opkg [options...] sub-command [arguments...]
where sub-command is one of:

Package Manipulation:
        update                  Update list of available packages
        upgrade <pkgs>          Upgrade packages
        install <pkgs>          Install package(s)
        configure <pkgs>        Configure unpacked package(s)
        remove <pkgs|regexp>    Remove package(s)
        flag <flag> <pkgs>      Flag package(s)
         <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)

```

需要注意的是，OPKG 需要 root 權限執行套件的安裝與管理，此限制在一般的 OpenWRT 環境中不成問題，但如果有對使用者權限進行限制，則需要特別注意。

在 OpenWRT 中，由於各裝置的架構不同，因此，就會需要不同的套件來支援，我們也可以用`opkg info`來看安裝套件的進一步資訊，以 tcpdump 為例:

```
# opkg info tcpdump
Package: tcpdump
Version: 4.9.2-1
Depends: libc, libpcap
Status: install user installed
Section: net
Architecture: mips_24kc
Size: 313899
Filename: tcpdump_4.9.2-1_mips_24kc.ipk
Description: Network monitoring and data acquisition tool
Installed-Time: 1539696689
```

我們可以看到其平台架構為: mips\_24kc，以及其安裝檔為: tcpdump\_4.9.2-1\_mips\_24kc.ipk。對於 OPKG 來說，安裝的套件為 .ipk 格式，ipk 是一個用以進行檔案壓縮的資料封裝格式，其中，包含了程式所需要的環境，設定檔，以及執行的封裝檔 (binaries)。

參考資料:

* <https://oldwiki.archive.openwrt.org/doc/techref/opkg>
* <https://zh.wikipedia.org/wiki/Opkg>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openwrt-nctu.gitbook.io/project/openwrt-compile-env/openwrt-opkg-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
