Skip to main content

Package Management

中文版

cosh-cli pkg provides structured package operations. It routes to dnf, apt, zypper, or Homebrew according to the detected platform and returns the common JSON envelope.

Commands

CommandPurpose
cosh-cli pkg install <package>Install a package
cosh-cli pkg remove <package>Remove a package
cosh-cli pkg search <query>Search package names
cosh-cli pkg list --installedList installed packages

Install or remove

Preview a change before executing it:

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

Run without --dry-run to apply the change. Package operations normally need root privileges. An install that finds the package already present still returns success and marks already_installed in the response.

The query is passed as one argument and uses a portable package-name pattern. The accepted pattern characters are package-name characters plus *, ?, [ and ]:

cosh-cli pkg search 'libssl*'
cosh-cli pkg search 'python3-?'
cosh-cli pkg search 'lib[0-9]*'

Backend-specific regular expressions, shell metacharacters, an empty query, and a query beginning with - are rejected. cosh-cli keeps whole-package-name matching consistent across supported backends.

List and errors

list --installed returns package names and versions. Search results also report whether each package is installed; a search result may omit its version, and a package listing may omit architecture or repository when the backend does not provide them.

Common failures are PkgNotFound, PkgBackendError, UnsupportedDistro, and PermissionDenied. Use error.hint in the response for the suggested next step. See Supported platforms for routing details and Output format for the response envelope.