Skip to content

Bun on Termux #8685

Closed
Closed

Description

@n0thhhing

What is the type of issue?

Documentation is missing

What is the issue?

Missing Docs for Termux users

Intro

While the primary focus of Bun is not currently on Android platforms like Termux, this aims to help Termux users install and use Bun smoothly.

installation

To begin, refer to the official Bun installation documentation using the following command:

curl -fsSL https://bun.sh/install | bash

However, after installation, attempting to use Bun may result in a Command not found error.

Solutions

Native Termux

  1. Start by addressing this issue with the only current viable solution — utilizing Termux's glibc package, which is detailed here.
  2. After installation, set an alias using grun to process the binary correctly.
  • Open your preferred configuration file (e.g., vim ~/.zshrc).
  • Add the alias:
alias bun="grun ~/.bun/bin/bun"

Downsides

While this solution has its usecases, there are some downsides to consider:

Packages Are Limited:

Due to limitations with grun, Bun may encounter difficulties reading and processing node modules, resulting in errors like:

❯ bun run index.ts
error: Cannot find package "some-package" from "/storage/emulated/0/Download/some_project/index.ts"
Limited Functionality:

As of now, due to native permissions and issues with grun, the Bun binary isn't fully processed. Consequently, certain operations may not work correctly:

  • Installing packages:
❯ bun add axios
bun add v1.0.25 (a8ff7be6)  🔍 axios [6/6]error: FailedToOpenSocket downloading package manifest axioserror: axios@ failed to resolve
  • Using features like bunx or Bun's REPL:
❯ bun repl
error loading current directoryerror: CouldntReadCurrentDirectory----- bun meta -----Bun v1.0.25 (a8ff7be6) Linux arm64 #1 SMP PREEMPT Wed Dec 27 11:31:51 UTC 2023BunxCommand:Elapsed: 11ms | User: 4ms | Sys: 12msRSS: 33.55MB | Peak: 9.72MB | Commit: 33.55MB | Faults: 12----- bun meta -----0   0x720c4e24f81   ???2   ???3   ???4   ???5   ???6   ???Search GitHub issues https://bun.sh/issues or ask for #help in https://bun.sh/discord

Proot distro

For installation and usage of Bun on Termux with a better approach, follow these steps:

  1. Install PRoot-Distro:
    Execute the following command to install PRoot-Distro using Termux's packages:
apt update && apt install proot-distro -y
  1. starting a session
proot-distro install ubuntu proot-distro login ubuntu # once installed you can use this anytime to start your Ubuntu terminal
  1. make sure bun is installed in the new session
  2. After installation, set an alias to run the Bun binary. Unlike native Termux, there are no external packages needed in this environment.
  • Open your preferred configuration file (e.g., vim ~/.zshrc).
  • Add the alias:
alias bun="~/.bun/bin/bun" # Or use the path where you have placed Bun's binaries
  1. Restart Your Shell:
    If you're using zsh, restart your shell to apply the changes:
exec zsh
  1. Verify Installation:
    Confirm the successful installation of Bun by running:
bun --version

downsides

  • Installing Packages:
    Due to Bun not being optimized for Android architectures, it lacks the necessary permissions to access node_modules. However, a fix is available. Update your configuration file with the following:
alias bun=bun_function
# Function to handle installations with the "--backend=copyfile" flag to prevent an "access denied" error during package installations.
bun_function() {
  if [ "$1" = "add" ]; then
    shift
    ~/.bun/bin/bun add --backend=copyfile "${@}"
  else
    ~/.bun/bin/bun "$@"
  fi
}

Additional Notes

This doesn't intend to force developers to prioritize Termux support but serves as a guide for those with limited access to environments like Termux. Ideas and fixes presented here are mostly original, with clarifications drawn from insightful comments on related issues.

credits:

Special thanks to issue #5085 for providing insights into fixing package installations. Additionally, credit goes to Denos fix for addressing similar usage issues.

Where Did You Find It?

This issue post aims to address missing documentation for Bun on Termux. It is *not intended to compel developers to prioritize Termux support but rather serves as guidance for users with limited access to environments like Termux. The outlined solutions and insights are derived from mostly original ideas with additional clarification from comments on related issues, particularly issue #5085 and Denos fix.

Activity

  1. added
    docsImprovements or additions to documentation
    on Feb 4, 2024
  2. Electroid commented on Feb 4, 2024

    @Electroid
    Contributor

    Thanks for opening this issue with detailed ideas/workarounds. We have too many other things to prioritize over Android/Termux. If we add it to our docs, there is an implicit expectation that it is a supported platform, when in reality it is not.

  3. n0thhhing commented on Feb 4, 2024

    @n0thhhing
    Author

    understandable,
    Considering the recent launch of Bun and other urgent matters, addressing concerns related to native Termux may not be the current primary focus. also, prioritizing support for Windows as of now is crucial to avoid potential complications from simultaneous extensive updates, which could negatively impact the ecosystem and workflow.

  4. CodeIter commented on May 16, 2024

    @CodeIter

    I made a shell script termux-pacman-glibc-setup.sh to setup glibc-runner with pacman on Termux and install Deno.JS and Bun.JS as a demo.

  5. marked Bun not running in termux #5085 as a duplicate of this issue on Jan 31, 2025
  6. unmarked Bun not running in termux #5085 as a duplicate of this issue on Jan 31, 2025
  7. tribixbite commented on May 30, 2025

    @tribixbite

    Image

    .bashrc:

    alias bum=bun_function
    # Function to handle installations with the "--backend=copyfile" flag to prevent an "access denied" error during package installations...that did not work for me:
    bun_function() {
      if [ "$1" = "add" ]; then
        shift
        ~/.bun/bin/bun add --backend=copyfile "${@}"
      else
        ~/.bun/bin/bun "$@"
      fi
    }
    
    export PATH=$HOME/.bun/bin:$PATH
    

    From a semi broken state with alias ubu='proot-distro login ubuntu' I ran:

    dpkg --configure -a
    pkg upgrade -y
    ubu
    rm -rf ~/.bun ~/.bun-install node_modules bun.lockb .bun-cache
    hash -r
    curl -fsSL https://bun.sh/install | bash
    
  8. kaan-escober commented on Feb 5, 2026

    @kaan-escober

    🎉 Solution for Running Bun Bundled Executables on Termux

    I've solved the problem of running bun build --compile binaries on Termux and documented the root cause.

    The Problem with grun

    When running Bun via grun (or explicit ld.so), bundled executables fail because:

    1. grun calls execve("/path/to/ld.so", ["ld.so", "./bun-app"], env)
    2. The kernel sets /proc/self/exe → ld-linux-aarch64.so.1
    3. Bun reads /proc/self/exe, opens ld.so, doesn't find the ---- Bun! ---- trailer
    4. Falls back to CLI mode instead of running embedded JavaScript
    $ grun ./my-app -e "console.log(require('fs').readlinkSync('/proc/self/exe'))"
    /data/data/com.termux/files/usr/glibc/lib/ld-linux-aarch64.so.1  # ← Wrong!

    ✅ Working Solution: Userland Exec Wrapper

    I created a Rust wrapper using the userland-execve crate that:

    1. Loads ld.so via mmap() instead of execve()
    2. Jumps to ld.so's entry point directly
    3. /proc/self/exe stays pointing to the wrapper binary
    4. Append the original binary's embedded JS data to the wrapper

    This works because the kernel only updates /proc/self/exe on execve() syscalls.

    Key trick for child processes: Use ld.so --library-path /glibc/lib instead of LD_LIBRARY_PATH so child processes (bash, ls, etc.) still use Bionic.

    Full technical writeup: https://github.com/AlyBadaworked/droid-to-glibc/blob/main/SOLUTION.md


    🔧 Proposed Simple Fix for Bun

    Instead of this complex workaround, Bun could add a simple env var override:

    // Before reading /proc/self/exe:
    if (bun.getenvZ("BUN_SELF_EXE")) |path| {
        return path;
    }

    Then Termux users could simply:

    export BUN_SELF_EXE="$(realpath ./my-app)"
    grun ./my-app

    I've opened an issue for this: #26752


    Impact

    This affects:

    • All bun build --compile binaries on Termux
    • The "Packages Are Limited" and "Limited Functionality" issues mentioned in this thread are likely related

    cc @cirospaciari

  9. Jobians commented on Feb 18, 2026

    @Jobians

    @kaan-escober How did you install bun on Termux first?

  10. Jobians commented on Feb 25, 2026

    @Jobians

    @tribixbite I already tried that, but it doesn’t seem to work.

    Every Bun command fails with the same error:

    ~ $ bun run test.ts
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)
    
    ~ $ bun repl
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)
    
    ~ $ bun feedback test.ts
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)
    
    ~ $ bun create vite
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)
  11. tribixbite commented on Feb 25, 2026

    @tribixbite

    @tribixbite I already tried that, but it doesn’t seem to work.

    Every Bun command fails with the same error:

    ~ $ bun run test.ts
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)
    
    ~ $ bun repl
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)
    
    ~ $ bun feedback test.ts
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)
    
    ~ $ bun create vite
    error loading current directory
    error: An internal error occurred (CouldntReadCurrentDirectory)

    https://github.com/tribixbite/bun-on-termux/blob/main/docs%2FTROUBLESHOOTING.md#couldntreadcurrentdirectory-error

    Note: "the wrapper" is referring to the custom wrapper in that repo

  12. kaan-escober commented on Feb 26, 2026

    @kaan-escober

    cool work @tribixbite. i just saw your repo.

  13. Happ1ness-dev commented on Mar 5, 2026

    @Happ1ness-dev

    Hi, I made a native wrapper that allows Bun to run in Termux without proot.

    It's based on kaan-escober's bun-termux-loader, but takes a slightly different approach, making both bun and bun built binaries "just work" without many problems.

    Constructive criticism and feedback are welcome :P
    https://github.com/Happ1ness-dev/bun-termux

  14. ElYaiko commented on May 9, 2026

    @ElYaiko

    Bump

    $ curl -fsSL https://bun.com/install | bash
    #=#=#                                                                  ##O#-#                                                                                                                                                                                                               #                                                                      ####                                                                   #########                                                              #############                                                          ##################                                                     ########################                                               ###############################                                        #####################################                                  #############################################                          ####################################################                   ##########################################################             ################################################################       ######################################################################## 100.0%
    bun was installed successfully to ~/.bun/bin/bun
    Run 'bun --help' to get started
    ~ $ bun --help
    bash: /data/data/com.termux/files/home/.bun/bin/bun: cannot execute: required file not found
    $ uname -a
    localhost 6.6.30-android15-8-g6b55ce738535-4k #1 SMP PREEMPT Thu Jan  1 00:00:00 UTC 1970 aarch64 Android
    
  15. RiskyMH commented on May 14, 2026

    @RiskyMH
    Contributor

    @ElYaiko can you try to manually install one of the android builds directly from gh releases, as I'm pretty sure the install script is the issue here now? For example the bun-linux-aarch64-android.zip should be what most need.

    https://github.com/oven-sh/bun/releases/tag/bun-v1.3.14

  16. kaan-escober commented on May 15, 2026

    @kaan-escober

    bun
    fish: Job 1, 'bun' terminated by signal SIGSYS (Bad system call)

    i tested the bun build but it throws a bad syscall error

  17. Jobians commented on May 15, 2026

    @Jobians

    @ErenayDev it works 😍

    Image
  18. Jobians commented on May 15, 2026

    @Jobians
  19. RiskyMH commented on May 15, 2026

    @RiskyMH
    Contributor
  20. RiskyMH commented on May 15, 2026

    @RiskyMH
  21. Anon4You commented on Jun 5, 2026

    @Anon4You
    Image

    I fixed it it's now working with glibc wrapper The output shows no EACCES errors
    Install from https://termuxvoid.github.io/

    Or you can download the deb and read it's postinst to build working bun Natively for future version https://github.com/termuxvoid/repo/blob/main/dists/termuxvoid/main/binary-all/bun.deb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsImprovements or additions to documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions