Termux Android Terminal Emulator

repository·master·Indexed 13 days ago

https://github.com/termux/termux-app

An Android terminal emulator and Linux environment that allows running a full Linux distribution without root access. Includes documentation on installation via F-Droid, GitHub, and Google Play, plugin integration (API, Boot, Float, Styling, Tasker, Widget), debugging with logcat, and executing commands from third-party apps via the RunCommandService.

Tokens
15.9K
Snippets
40
Records
68
Agent score
99%

What's inside Termux

  1. Understand Termux App and Plugins

    master

    The core Termux application provides the terminal emulation and user interface. To extend its functionality, you can install optional plugin apps. Each plugin adds specific capabilities to the Termux environment:

    • Termux:API: Provides access to Android system APIs.
    • Termux:Boot: Allows running scripts on device boot.
    • Termux:Float: Enables floating window mode.
    • Termux:Styling: Allows customizing terminal appearance.
    • Termux:Tasker: Integration with the Tasker automation app.
    • Termux:Widget: Adds Termux shortcuts to Android home screen widgets.
  2. Avoid mixing Termux installation sources

    master

    Termux and its plugins share the same sharedUserId (com.termux). Consequently, all APKs (the main app and any plugins) must be signed with the same key to work together.

    Do not mix sources (e.g., installing the app from F-Droid and a plugin from GitHub). Mixing sources will result in installation errors such as:

    • App not installed
    • Failed to install due to an unknown error
    • INSTALL_FAILED_UPDATE_INCOMPATIBLE
    • INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
    • signatures do not match previously installed version

    If you need to switch sources, you must uninstall all existing Termux apps and plugins before installing the new ones from the chosen source. It is recommended to Back up Termux before doing so.

  3. Install Termux via F-Droid or GitHub

    master

    Termux can be installed through several channels. Note that this repository contains the application (UI and terminal emulation), while the Linux packages installed within the environment are managed by the termux-packages repository.

    Available installation methods:

    • F-Droid: The recommended way to install Termux.
    • GitHub: Available via the repository releases.
    • Google Play Store: Currently an experimental branch and not the primary distribution method.
  4. Install Termux via Google Play Store (Experimental)

    master

    A build of Termux is available on Google Play for Android 11+ devices.

    Warning: This is an experimental branch with missing functionality and bugs compared to the stable F-Droid or GitHub builds. It is built from a separate repository (termux-play-store).

    Managing Updates: Google Play may attempt to update existing F-Droid installations, which will fail due to sharedUserId differences. To prevent failed update attempts, go to the Termux app page in the Play Store, tap the three-dot menu, and disable Enable auto update.

  5. Install Termux via GitHub

    master

    Termux can be obtained from GitHub via GitHub Releases or GitHub Build Action workflows.

    Selection Guide:

    • Android >= 7: Install apt-android-7 variants.
    • Android 5 and 6: Install apt-android-5 variants.

    Sources:

    • GitHub Releases: Found under the Assets dropdown of a release. These are stable versions.
    • GitHub Build Action: Found in the Artifacts section of a workflow run. These are bleeding-edge builds from recent commits. You must be logged into a GitHub account to download artifacts.

    Security Warning: GitHub APKs are signed with a shared test key. Do not install Termux GitHub builds distributed via unofficial channels like Telegram, as they could be malicious.

    https://github.com/termux/termux-app/releases
  6. Uninstall Termux completely

    master

    To completely remove Termux from your device or to switch to a different installation source, you must uninstall all related APKs.

    1. Go to Android Settings -> Applications.
    2. Search for termux in the application list.
    3. Uninstall the main Termux app and any and all plugins you may have installed. Even if you do not remember installing plugins, check the list thoroughly to ensure a clean switch between sources.
  7. Install Termux via F-Droid

    master

    Termux can be installed from F-Droid. You do not need to install the F-Droid app itself; you can download the Termux APK directly from the F-Droid website.

    Important Notes:

    • F-Droid releases are built by F-Droid, not the Termux maintainers, so updates may lag behind GitHub releases by days or weeks.
    • F-Droid only provides a universal APK (works on all architectures), resulting in a larger installation size (~180MB including bootstrap).
    • To ensure updates are detected, disable battery optimizations for the F-Droid app and manually pull down to refresh in the Updates tab.
    https://f-droid.org/en/packages/com.termux/
  8. Generate a debug report for issue reporting

    master

    If you are reporting an issue, you can automatically generate a report containing stat info and a logcat dump:

    1. Long-hold the terminal's options menu.
    2. Select More -> Report Issue.
    3. Select YES when prompted to add debug info.

    If the generated report is too large, you can use the Save To File option in the context menu (three dots on the top right) of the ReportActivity to manually save and share the file.

    Important: When reporting issues, always provide the complete text report. Submitting only screenshots of error reports will likely result in the issue being closed or deleted.

  9. Configure command execution results via ResultConfig

    master

    The ResultConfig class is used to define how the results of a shell command should be delivered to a consumer. Results can be delivered in two primary ways:

    1. Via a PendingIntent: The results are sent back to a specific package using an Android PendingIntent. You must specify the keys used to retrieve specific data (like stdout, stderr, or exitCode) from the resulting android.os.Bundle.
    2. Via File System: The results are written to a directory on the device. You can configure whether the output is written to a single file or split into multiple files (e.g., separate files for stdout and stderr).

    Use isCommandWithPendingResult() to check if the configuration specifies either a PendingIntent or a resultDirectoryPath.

  10. Understand the Termux shell environment composition

    master

    The Termux shell environment is a layered configuration that builds upon the standard Android shell environment. It includes:

    1. Android Environment: The base system environment variables.
    2. Termux App Environment: Variables specific to the Termux application.
    3. Termux API Environment: Variables provided by the Termux:API package.
    4. Core Termux Variables:
      • HOME: Set to the Termux home directory.
      • PREFIX: Set to the Termux prefix directory.
      • TMPDIR: Set to the Termux temporary directory (unless in isFailSafe mode).

    Path and Library Behavior:

    • Android 7+: The PATH is set to the Termux bin prefix directory, and LD_LIBRARY_PATH is removed by default to rely on DT_RUNPATH for binary dependencies.
    • Android 5/6 (Legacy): The PATH includes both the Termux bin prefix and an /applets directory (for BusyBox), and LD_LIBRARY_PATH is set to the Termux lib prefix directory.
  11. How TermuxService manages terminal session clients

    master

    The TermuxService manages the connection between the terminal sessions and the UI (the TermuxActivity). This is handled via a TermuxTerminalSessionClient.

    • When the Activity is bound: The service uses setTermuxTerminalSessionClient(TermuxTerminalSessionActivityClient) to provide a fully implemented client that allows the UI to interact with terminal sessions. This updates all existing sessions via updateTerminalSessionClient.
    • When the Activity is destroyed: The service calls unsetTermuxTerminalSessionClient() to clear activity references, preventing memory leaks. It reverts sessions to a fallback TermuxTerminalSessionServiceClient.
    • Retrieving the client: Use getTermuxTerminalSessionClient() to get the current client. It returns the TermuxTerminalSessionActivityClient if the activity is bound, otherwise it returns the fallback TermuxTerminalSessionServiceClient.