Skip to content

Instantly share code, notes, and snippets.

@omar-azmi
Last active September 18, 2025 08:24
Show Gist options
  • Select an option

  • Save omar-azmi/9510958fe24a7374856ccc75217330d5 to your computer and use it in GitHub Desktop.

Select an option

Save omar-azmi/9510958fe24a7374856ccc75217330d5 to your computer and use it in GitHub Desktop.
installing and setting up deno on android via termux
# NOTE: to run this script remotely (without copy and pasting) simply execute:
# curl -fsSL "https://gist.githubusercontent.com/omar-azmi/9510958fe24a7374856ccc75217330d5/raw/setup_deno_on_termux.sh" | sh
# the following shell script will install the deno javascript runtime to your termux environment on android.
# after that, it will patch the deno binary to use android/termux compatible libc shared libraries (which we will download beforehand)
# finally, we will append the path to the deno library onto the PATH environment variable in your local `./.bachrc` file, so that `deno` will be available as a command on every terminal session.
# the proceedure for making deno compatible with termux was gathered from the following resources:
# - "https://github.com/denoland/deno/issues/19759"
# - "https://gist.github.com/CodeIter/ccdcc840e432288ef1e01cc15d66c048"
# 1. install pre-requisites:
# - `glibc-repo` and `glibc` provide the termux-compatible shared libraries for libc (a dynamic dependency of deno)
# - `patchelf` lets us patch the deno binary to use an alternate location for its dynamic dependencies on libc
pkg install --yes glibc-repo
pkg install --yes glibc
pkg install --yes patchelf
# 2. download and install deno.
# we don't use the official script because it immediately executes deno to carry out additional tasks.
# but we cannot run the deno binary here until it has been patched.
target="aarch64-unknown-linux-gnu"
deno_version="$(curl -s https://dl.deno.land/release-latest.txt)"
deno_uri="https://dl.deno.land/release/${deno_version}/deno-${target}.zip"
deno_install="${DENO_INSTALL:-$HOME/.deno}"
bin_dir="${deno_install}/bin"
exe="${bin_dir}/deno"
if [ ! -d "${bin_dir}" ]; then mkdir -p "${bin_dir}"; fi
curl --fail --location --progress-bar --output "${exe}.zip" "${deno_uri}"
unzip -d "${bin_dir}" -o "${exe}.zip"
chmod +x "${exe}"
rm "${exe}.zip"
echo "Deno was installed successfully to: \"${exe}\""
# 3. patch the deno binary to use the termux-compatible libc shared libraries
patchelf --set-rpath "${HOME}/../usr/glibc/lib" --set-interpreter "${HOME}/../usr/glibc/lib/ld-linux-aarch64.so.1" "${exe}"
# 4. adding shell configurations to your `~/.bashrc`
bashrc_file="${HOME}/.bashrc"
touch "${bashrc_file}"
echo "export DENO_INSTALL=\"${deno_install}\"" >> "${bashrc_file}"
echo "export PATH=\"\${PATH}:${bin_dir}\"" >> "${bashrc_file}"
echo "unset LD_PRELOAD" >> "${bashrc_file}" # I think this disables dynamic library preloading, which is necessary for any patched binaries
# 5. apply variable declarations and configurations to the current session as well
export DENO_INSTALL="${deno_install}"
export PATH="${PATH}:${bin_dir}"
unset LD_PRELOAD
@iacobucci
Copy link

Its giving me:
deno: error while loading shared libraries: /data/data/com.termux/files/usr/glibc/lib/libc.so: invalid ELF header

@omar-azmi
Copy link
Author

Could you try installing this on the latest version of termux (v0.119-beta3)?
I just tried using my script on an old phone running an old version of termux (v0.101), and it was failing to recognise the glibc-repo package, leading to there being no dynamic version of libc being installed.
But after updating my termux (clean re-installation) to the latest version on my old phone, the script worked just fine.

@omar-azmi
Copy link
Author

Also, do note that the deno command will not be immediately available on the terminal session in which you run the script.
It'll only become available in the next new terminal session.

@iacobucci
Copy link

Could you try installing this on the latest version of termux (v0.119-beta3)? I just tried using my script on an old phone running an old version of termux (v0.101), and it was failing to recognise the glibc-repo package, leading to there being no dynamic version of libc being installed. But after updating my termux (clean re-installation) to the latest version on my old phone, the script worked just fine.

Thanks, idk why but from version 118 the update is telling me that its conflicting... Should i wait for version 120 of termux or something? 😂

@omar-azmi
Copy link
Author

That seems unusual; because I just tried my script on a clean installation of termux 0.118.3 (from F-Droid), and it worked as expected.
And then, I also updated (without uninstalling) to 0.119-beta3, and the apk installer never complained about a conflict between the two versions.
More so, the pre-exising installation of deno continued working after the update.

I think you might be installing your apk from a source that is different from the original installation source.
For instance, you generally cannot download an apk update from F-Droid or Github when the original apk was installed through the Play Store, and vice versa. (this is often due to a signature mismatch. which happens because (i think) google signs the play store apks with their own keys)

Moreover, when running termux for the first time after a fresh installation, make absolutely sure not to press any button nor tap on the phone while the "installing bootstrap packages" dialog (or something similar) is on the screen. Because I've read a few posts that claim that interupting termux during its first boot leads to the apt package manager not working correctly.

Hope this help, because otherwise I don't know much about termux (nor the package manager) myself to help you diagnose further.

@iacobucci
Copy link

Thank you for your thorough response haha! Well my build is from fdroid, and i dont know where exactly things went wrong, if in the first bootstrap or in some incompatibilities with the oem distro im testing on (its nothing os 3.something). Along the elf patcher not working, i also experience this annoying crash of the app alltogether at times (im going seriously off topic here). Ill post some updates in this thread if i have any success with your script or, roughly, your method!

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