Termux-packages: apt install comand not working in root

Created on 19 Dec 2016  路  21Comments  路  Source: termux/termux-packages

Sometimes i try to excute some commands that needs root access, and when try to excute them i get an error. Im trying to install nmap for example but it tells me apt not found. Is that a bug or miss configuration?

root

Most helpful comment

@soaringowl2145 I'd recommend using https://github.com/st42/termux-sudo for running commands as root

You can commands with sudo <command> or drop to a root shell with the same $PATH by using sudo su

All 21 comments

apt is not meant to be run as root and for the love of god don't do it. When you drop into a root shell, termux's su wrapper resets the PATH env var so you cannot call binaries from $PREFIX/bin dir. You can disable this by editing the su wrapper (its a shell script) or manually adding $PREFIX/bin to PATH in the root shell.

@vishalbiswas What is the exact path that this file is located?

@soaringowl2145 /data/data/com.termux/files/usr/bin/su or you can which su

So do I make another line with this exact text?

$PREFIX/bin

--- /data/data/com.termux/files/usr/bin/su
+++ su.e
@@ -1,12 +1,12 @@
 #!/data/data/com.termux/files/usr/bin/sh

-unset LD_LIBRARY_PATH
+#unset LD_LIBRARY_PATH

 for p in /system/xbin/su /su/bin/su /sbin/su /magisk/.core/bin/su
 do
        if [ -x $p ]; then
                # The su tool may require programs in PATH:
-               PATH=/sbin/su:/su/bin:/su/xbin:/system/bin:/system/xbin \
+               PATH=/sbin/su:/su/bin:/su/xbin:/system/bin:/system/xbin:$PATH \
                        exec $p $@
        fi
 done

This should do it. Keep in mind I don't recommend doing this.

Some packages REQUIRE root access. How do you reccomend we use those then?

@soaringowl2145 I don't think any one of termux's packages require root.

@vishalbiswas macchanger does to change the Mac address.

@soaringowl2145 You got me there. You can also execute the su binary directly like /system/xbin/su -c "macchanger -r"

@vishalbiswas sh: macchanger: not found

what did you run?

@vishalbiswas /system/xbin/su -c "macchanger -r"

Your su binary resets env internally it seems. Does patching the wrapper helps?

At this point I just want to leave the defaults the way they are.

/system/xbin/su -i -c "macchanger" maybe this helps

Thank you very much @vishalbiswas

@vishalbiswas Why exactly do you not recommend changing the su wrapper?

Suppose you install a package as root. It may modify the fs permissions for $PREFIX, which may later cause failure in installing packages

@vishalbiswas So if I only use it to run commands as root I should be fine, right?

yes, you will mostly be fine when using programs that explicitly require root

@soaringowl2145 I'd recommend using https://github.com/st42/termux-sudo for running commands as root

You can commands with sudo <command> or drop to a root shell with the same $PATH by using sudo su

Was this page helpful?
0 / 5 - 0 ratings

Related issues

newmania picture newmania  路  3Comments

divyakutty picture divyakutty  路  3Comments

jackbrycesmith picture jackbrycesmith  路  3Comments

roalyr picture roalyr  路  3Comments

thurask picture thurask  路  3Comments