Learn Termux package management
masterapt or pkg commands and troubleshooting common errors like repository is under maintenance or down, refer to the official Package Management Wiki.repository·master·Indexed 12 days ago
https://github.com/termux/termux-packagesScripts and patches used to build software packages for the Termux Android application environment. Includes documentation on package management, build configurations for packages like calc, and internal shell functions for managing scoped environment variables and app version information.
apt or pkg commands and troubleshooting common errors like repository is under maintenance or down, refer to the official Package Management Wiki.The update process follows a specific lifecycle to ensure stability and efficiency:
TERMUX_PKG_AUTO_UPDATE=true in their build.sh.auto update failing for that package.scripts/buildorder.py to find its dependencies and ensures they are updated first.termux_pkg_auto_update() function (defined in the package's build.sh) is called to perform the actual version upgrade logic.Auto update failing for <package_name> with the error logs included in a collapsible <details> block.When building calc, you can specify the location and flags for the Readline library to ensure proper terminal interaction support.
Variables:
READLINE_LIB: The library flags for linking. Defaults to -L${PREFIX}/lib -lreadline.READLINE_EXTRAS: Additional library flags. Defaults to -lhistory -lncurses.READLINE_INCLUDE: The include path for Readline headers. Defaults to -I${PREFIX}/include.READLINE_LIB= -L${PREFIX}/lib -lreadline
READLINE_EXTRAS= -lhistory -lncurses
READLINE_INCLUDE= -I${PREFIX}/includeThe calc package Makefile uses several variables to define the installation hierarchy. Most paths are relative to PREFIX. If you are building the package, you can override these variables to redirect the installation.
Key installation variables:
PREFIX: The base installation directory. Defaults to /usr/local.BINDIR: The directory for executable binaries. Defaults to ${PREFIX}/bin.LIBDIR: The directory for libraries. Defaults to ${PREFIX}/lib.INCDIR: The directory for header files. Defaults to ${PREFIX}/include.CALC_SHAREDIR: The directory for shared data. Defaults to ${PREFIX}/lib/calc.MANDIR: The directory for man section 1 pages. Defaults to ${PREFIX}/share/man/man1.T: The top-level directory under which calc will be installed. This is set to ${DESTDIR} by default.PREFIX ?= /usr/local
BINDIR= ${PREFIX}/bin
LIBDIR= ${PREFIX}/lib
INCDIR= ${PREFIX}/include
CALC_SHAREDIR= ${PREFIX}/lib/calc
MANDIR= ${PREFIX}/share/man/man1
T=${DESTDIR}The update-packages script is highly configurable through environment variables. These allow you to control the build process, update logic, and automation behavior.
BUILD_PACKAGES: If set to true, the script will attempt to build the updated packages.GIT_COMMIT_PACKAGES: If set to true, the script will commit changes to Git.GIT_PUSH_PACKAGES: If set to true, the script will push changes to the remote repository.CREATE_ISSUE: If set to true (and running in GitHub Actions), the script will create a GitHub issue if an update fails.TERMUX_PKG_AUTO_UPDATE: Set to true to enable auto-updates. Disabled by default.TERMUX_PKG_UPDATE_METHOD: Force a specific update method: repology, github, or gitlab.TERMUX_PKG_UPDATE_TAG_TYPE: Specify the tag type to use: latest-release-tag, latest-regex, or newest-tag.TERMUX_PKG_UPDATE_VERSION_REGEXP: Regexp used to extract the version with grep -oP.TERMUX_PKG_UPDATE_VERSION_SED_REGEXP: Regexp used to extract the version with sed.TERMUX_ARCH: The architecture to test updates for (default: aarch64).GITHUB_TOKEN: Required for GitHub GraphQL API calls and interacting with GitHub issues via the gh CLI.The termux_core__bash__set_shell_command_args_array function converts a shell-style command argument string into a properly formatted bash indexed array. It handles complex cases involving spaces and shell special characters by using xargs to ensure correct parsing.
termux_core__bash__set_shell_command_args_array <command_args_array_variable_name> <command_args_label> <command_args_string><command_args_array_variable_name>: The name of the bash array variable to be populated.<command_args_label>: A label used for error reporting.<command_args_string>: The raw string containing the command arguments.", ', *, ?, !, \[, \], +) or spaces that require quoting, it uses xargs to parse the arguments correctly.xargs implementation in the current environment is capable of correct parsing before proceeding.# Example: Converting a complex string to an array
my_args=()
cmd_str="'arg with space' 'arg with \"quotes\"'"
termux_core__bash__set_shell_command_args_array my_args "my_command" "$cmd_str"
# my_args is now an array: ("arg with space" "arg with \"quotes\"")| Flag | Argument | Description |
|---|---|---|
<package> ... | Required | Increments TERMUX_PKG_REVISION for the specified package(s). |
--dependencies <package> | Required | Increments TERMUX_PKG_REVISION for all packages that list <package> in their TERMUX_PKG_DEPENDS, TERMUX_PKG_BUILD_DEPENDS, or TERMUX_SUBPKG_DEPENDS variables. |
-d <package> | Required | Alias for --dependencies. |
--help or -h | Optional | Displays the usage guide. |
When using the get-value command, the <scoped_var_scope_mode> argument must match one of the following patterns to correctly identify the environment variable scope:
| Pattern | Description |
|---|---|
s=[A-Z]*_APP__ | Environment variable scope starting with s= and ending with _APP__ |
ss=APP__ | Sub-scope mode |
ss=[A-Z]*_APP__ | Sub-scope mode starting with ss= and ending with _APP__ |
cn=[a-z]*-app | Supported component name starting with cn= and ending with -app |
s=[A-Z]*_APP__
ss=APP__
ss=[A-Z]*_APP__
cn=[a-z]*-appThe build process uses standard system utilities. You can override these if necessary:
RANLIB: The utility used to perform actions on a *.a link library. Defaults to ranlib.AR: The archiver utility. Defaults to ar.LDCONFIG: The utility to configure dynamic linker run-time bindings. Note that in this configuration, it is explicitly set to an empty string (LDCONFIG=).RANLIB?=ranlib
AR?= ar
LDCONFIG=When using the cn= prefix in the <scoped_var_scope_mode> argument, the function maps the component to a specific sub-scope prefix. This ensures variables are correctly namespaced according to the Termux component they belong to.
| Mode | Sub-scope Prefix |
|---|---|
cn=termux | _ |
cn=termux-app | APP__ |
cn=termux-api-app | API_APP__ |
cn=termux-float-app | FLOAT_APP__ |
cn=termux-gui-app | GUI_APP__ |
cn=termux-tasker-app | TASKER_APP__ |
cn=termux-widget-app | WIDGET_APP__ |
cn=termux-x11-app | X11_APP__ |
cn=termux-core | CORE__ |
cn=termux-exec | EXEC__ |
The following exit codes are returned by the function:
| Code | Constant | Description |
|---|---|---|
64 | EX__USAGE | Invalid argument count or invalid command/scope mode provided |
69 | EX__UNAVAILABLE | The termux-apps-info.env file is missing or cannot be sourced |
64 # EX__USAGE
69 # EX__UNAVAILABLEWhen using the termux_core__sh__termux_apps_info_app_version_name function, the following exit codes are returned:
64 (EX__USAGE): Returned when invalid arguments are passed, an unknown option is used, or the required argument count is not met.81 (C_EX__NOT_FOUND): Returned when a valid version name cannot be found for the specified scope. In this case, if an output_mode variable was provided, it is set to an empty string.