← All Modules

apt

apt-get / dpkg-query wrapper builtin. No require() needed — apt is a global table. Linux (Debian/Ubuntu) only. Introduced in v0.15.5.

Namespace note: This documents the apt.* builtin global (apt-get/dpkg-query wrapper). For the assay.apt Lua stdlib (apt-repo Packages-index reader), see apt_index.md.

Mutating operations (install, remove, update, add_source) require root. All functions are async at the Rust level; mlua drives them as Lua coroutines so callers write straight-line code.

Query / inspect

Source management

Mutating apt-get operations

All three functions return {status=integer, stdout=string, stderr=string, timed_out=boolean}, matching the shell.exec result shape. timed_out is always false (timeout not yet implemented for apt — apt-get's own behaviour applies).

Test-only helpers

These are exported for unit tests and not intended for production use:

Example

-- Check before installing
local q = apt.query("curl")
if not q.installed then
  apt.add_source({
    id          = "mycorp",
    source_list = "deb [signed-by=/usr/share/keyrings/mycorp.gpg] https://pkgs.mycorp.com/debian stable main",
    key_path    = "/opt/mycorp/mycorp.gpg",
  })
  apt.update()
  local r = apt.install({ names = { "curl", "jq" } })
  if r.status ~= 0 then
    error("apt install failed:\n" .. r.stderr)
  end
end

-- Check for pending upgrades
for _, pkg in ipairs(apt.list_upgradable()) do
  print(pkg.name, pkg.current, "->", pkg.candidate)
end