Skip to main content

Package Management

The cosh-cli pkg subsystem provides cross-distribution package management operations. It automatically detects the current distribution and routes to the corresponding package manager backend (dnf / apt-get / zypper / brew).

Command List

CommandDescription
cosh-cli pkg install <name>Install package
cosh-cli pkg remove <name>Remove package
cosh-cli pkg search <query>Search packages
cosh-cli pkg list --installedList installed packages

install

Install a specified package.

cosh-cli pkg install nginx
cosh-cli pkg install nginx --dry-run

Success output:

{
"ok": true,
"data": {
"package": "nginx",
"version": "1.24.0",
"already_installed": false,
"dependencies_installed": []
},
"meta": { "subsystem": "pkg", "duration_ms": 5200, "distro": "alinux", "dry_run": false }
}

If the package is already installed, already_installed is true and the command still returns success.

remove

Remove a specified package.

cosh-cli pkg remove nginx
cosh-cli pkg remove nginx --dry-run

Success output:

{
"ok": true,
"data": {
"package": "nginx",
"version_removed": "1.24.0",
"dependencies_removed": []
},
"meta": { "subsystem": "pkg", "duration_ms": 2100, "distro": "ubuntu", "dry_run": false }
}

Search available packages. Results include installation status.

cosh-cli pkg search "web server"

Output:

{
"ok": true,
"data": {
"packages": [
{ "name": "nginx", "version": "1.24.0", "description": "...", "installed": true },
{ "name": "apache2", "version": "2.4.58", "description": "...", "installed": false }
],
"total": 2
},
"meta": { "subsystem": "pkg", "duration_ms": 800, "distro": "ubuntu", "dry_run": false }
}

list

List installed packages.

cosh-cli pkg list --installed

Output:

{
"ok": true,
"data": {
"packages": [
{ "name": "nginx", "version": "1.24.0" },
{ "name": "curl", "version": "8.5.0" }
],
"total": 2
},
"meta": { "subsystem": "pkg", "duration_ms": 300, "distro": "centos", "dry_run": false }
}

Backend Mapping

Operationdnfapt-getzypperbrew
installdnf install -yapt-get install -yzypper install -ybrew install
removednf remove -yapt-get remove -yzypper remove -ybrew uninstall
searchdnf search -qapt-cache searchzypper searchbrew search
listdnf list installed -qdpkg-query -Wzypper se --installed-onlybrew list --versions

Error Handling

  • Package not found returns PkgNotFound, hint suggests searching
  • Package manager execution failure returns PkgBackendError, recoverable: true
  • Unsupported distribution returns UnsupportedDistro