sudo Install Docs
March 6, 2025 · View on GitHub
The sudo install instructions are available below. For build instructions, check build docs.
Contents
Install Dependencies
Using sudo in Termux shells only has the following dependencies.
- Termux app version: minimum
>= 0.100, recommended>= 0.119.0. bashversion:>= 4.1.- A
subinary that supports the-c,--shell,--preserve-environmentand--mount-masteroptions. Magisk and SuperSU are recommended and theirsubinaries support the required options. Note that the limitedsuprovided by Android debug builds foradb rootdoes not support these options. Checksusearch paths for more info.
However, to use sudo with Termux:Tasker plugin app and RUN_COMMAND Intent requires the following app versions to be installed. Check Passing Arguments section and Termux:Tasker Setup Instructions section for details.
- Tasker app version:
>= 5.9.4.beta - Termux:Tasker app version:
>= 0.5
Install Sources
sudo can be installed from the following sources.
The Termux Packages Repository is the recommended way to install sudo.
The Termux app version >= v0.119.0 exports path environment variables like $TERMUX_ROOTFS, $TERMUX_HOME and $TERMUX_PREFIX under the TERMUX_ env root scope ($TERMUX_ENV__S_ROOT). sudo version >= 1.0.0 uses these dynamic paths instead of relying on hardcoded com.termux paths, which will not work if Termux is built for a different rootfs or for a fork. In future, multiple rootfs support may be added in Termux app as well. The hardcoded com.termux paths refers to /data/data/com.termux/* paths for the upstream Termux app with the com.termux app package name.
- If running in Termux app version
< 0.119.0where environment variables are not exported:- If
sudois built with Termux Packages Build Infrastructure, then placeholder path values that are replaced during build time are used. - If
sudois built On Device Withmakeor downloaded frommasterbranch or GitHub Releases, then hardcoded/data/data/com.termux/*paths are used.
- If
- If running in Termux app version
>= 0.119.0where environment variables are exported:- If
sudois built with Termux Packages Build Infrastructure, then environment variables are used if set, with a fallback to placeholder path values that are replaced during build time. - If
sudois built On Device Withmakeor downloaded frommasterbranch or GitHub Releases, then environment variables are used if set, with a fallback to hardcoded/data/data/com.termux/*paths.
- If
Hence, if sudo is not built with the Termux Packages Build Infrastructure, then it will not work in Termux app forks that have not merged the changes done in Termux app version >= 0.119.0 for exporting path environment variables into their own apps.
Termux variables are set in the sudo_set_termux_env_variables function of the sudo script, which internally calls the termux_gtsev_bash__get_termux_scoped_env_variable() function that is used by the termux-get-termux-scoped-env-variable.bash util provided by the termux-core package. The @*@ placeholders (like @TERMUX__ROOTFS@) in the sudo_set_termux_env_variables function exist so that they are replaced during build time by the Termux build infrastructure through the Makefile. Check termux-get-termux-scoped-env-variable usage docs for more info.
Termux Packages Repository
To install sudo package from the main channel of the Termux packages repository, run the following commands.
pkg install sudo
GitHub
The sudo file should be installed in termux bin directory ${TERMUX__PREFIX:-$PREFIX}/bin. It should have Termux app (u<userid>_a<appid>) user (like u0_a100) uid:gid ownership and have executable (700/rwx------) permission before it can be executed.
Basic
The Basic way is the recommended way to install sudo from GitHub, especially if you have limited understanding of shell commands.
curl will automatically be installed to download sudo.
Download sudo from the latest GitHub Releases and convert it into an executable. Copy all the commands and run them together in the shell.
pkg install curl && \
install_dir="${TERMUX__PREFIX:-$PREFIX}/bin" && \
mkdir -p "$install_dir" && \
rm -f "$install_dir/sudo" && \
curl -L 'https://github.com/agnostic-apollo/sudo/releases/latest/download/sudo' -o "$install_dir/sudo"
owner="$(stat -c "%u" "$install_dir")" && chown "$owner:$owner" "$install_dir/sudo" && \
chmod 700 "$install_dir/sudo" && \
termux-fix-shebang "$install_dir/sudo"
Advance
- Set install directory path and create it and delete any existing
sudofile.
install_dir="${TERMUX__PREFIX:-$PREFIX}/bin" && \
mkdir -p "$install_dir" && \
rm -f "$install_dir/sudo"
-
Download the
sudofile. If usingcurl, then it must be installed to downloadsudo. Runpkg install curlto installcurl.-
Using
curlfrom GitHub Releases with a non-root shell.-
Latest release:
curl -L 'https://github.com/agnostic-apollo/sudo/releases/latest/download/sudo' -o "$install_dir/sudo" -
Specific release:
curl -L 'https://github.com/agnostic-apollo/sudo/releases/download/v0.1.0/sudo' -o "$install_dir/sudo"
-
-
Manually from GitHub Releases listed under the
Assetsdropdown menu to the android download directory and then copy it to install directory usingcatcommand or a root file browser. Termux app must havestoragepermission if runningcatcommand.cat "/storage/emulated/0/Download/sudo" > "$install_dir/sudo" -
Using
curlfrommasterbranch (may be unstable) with a non-root shell.curl -L 'https://github.com/agnostic-apollo/sudo/raw/master/sudo' -o "$install_dir/sudo"
-
-
Set
Termux app (u<userid>_a<appid>)user ownership and executable (700/rwx------) permission.-
If you used
curlorcatto copy the file, then use a non-root shell to set ownership and permissions withchownandchmodcommands respectively:owner="$(stat -c "%u" "$install_dir")" && chown "$owner:$owner" "$install_dir/sudo" && chmod 700 "$install_dir/sudo"; -
If you used a root file browser to copy the file, then use
suto start a root shell to set ownership, permissions and SeLinux context (1, 2) for Termux user withchown,chmodandrestoreconcommands respectively:owner="$(stat -c "%u" "$install_dir")" && su -c "chown \"$owner:$owner\" \"$install_dir/sudo\" && chmod 700 \"$install_dir/sudo\" && restorecon \"$install_dir/sudo\"";
-
-
Replace
#!/usr/bin/bashshebang insudoscript with path tobashunder the current Termux rootfsbinpath by runningtermux-fix-shebangon it so thatsudoworks properly even iflibtermux-exec.sois not set in$LD_PRELOAD. Checktermux-execLinux vs Termuxbinpathsandtermux-taskerTermux Environmentdocs for more info.termux-fix-shebang "$install_dir/sudo"