I used pip install ... and pkg install ... on tsu.
And then when I switched to non-root mode, pip, pip2 .. and pkg, apt .. give an error.
pip error → PermissionError: [Errno 13] Permission denide: '/data/data/com.termux/files/usr/lib/python3.6/site-packages/XlsxWriter-0.9.8.dist-info
pkg →
All packages are up to date.
W: chmod 0600 of file /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_InRelease failed - Item::QueueURI (1: Operation not permitted)
W: chmod 0644 of file /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_InRelease failed - 201::URIDone (1: Operation not permitted)
You should be really careful when running under root in Termux (and Android in general), this will break things such as apt and pip, and there is no point in doing so - you can install Termux packages fine without being root.
In the future we may add a warning to the pkg command to avoid it being run as root by mistake, for now one just have to avoid it.
I'm having the same issue. I accidentally updated packages not realizing I was a root user (which generally works fine in my Linux OS). I think this is a serious pitfall that should be handled more gracefully.
Is there any way I can revert the permissions/ownership of the affected files without having to re-install Termux completely?
@Monsieur-Moony There is a tool like chown or chmod
if you let's see the folder ls -al /data/data/com.termux/files/usr/lib/python3.6/site-packages
or ls -al /data/data/com.termux/files/usr/var/lib/apt/lists/ you will see that this folder is owned by the user ROOT.
It is necessary to correct it through
chown u1_23456:u1_23456 -R /data/data/com.termux/files/usr/lib/python3.6/site-packages
then give the rights to read
chmod 755 -R /data/data/com.termux/files/usr/lib/python3.6/site-packages
and so you need to fix all the folders that give the Permission denide.
that to find out your current user and group, write id.
@Deathlive Thanks for the help, however the bug strangely persists. To expand on the error, this is what I am seeing on pkg update previously and currently:
Get:1 http://termux.net stable InRelease [1687 B]
Get:3 http://termux.net stable/main arm Packages [59.2 kB]
Hit:2 http://termux.net stable/main all Packages
Ign:2 http://termux.net stable/main all Packages
Hit:2 http://termux.net stable/main all Packages
Ign:2 http://termux.net stable/main all Packages
Hit:2 http://termux.net stable/main all Packages
Reading package lists... Error!
E: Could not open file /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_InRelease - open (13: Permission denied)
E: Unable to determine file size for fd -1 - fstat (9: Bad file descriptor)
W: Problem unlinking the file /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_InRelease - TransactionStates-Cleanup (13: Permission denied)
W: Problem unlinking the file /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_main_binary-arm_Packages - TransactionStates-Cleanup (13: Permission denied)
W: Problem unlinking the file /data/data/com.termux/files/usr/var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /data/data/com.termux/files/usr/var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
E: can not open /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_InRelease - fopen (13: Permission denied)
E: The package lists or status file could not be parsed or opened.
Also here are the current permissions/ownership of files in the .../lists/ directory:
total 284
-rw------- 1 u0_a203 u0_a203 0 Jun 4 08:27 lock
drwx------ 2 u0_a203 u0_a203 4096 Nov 8 10:36 partial
-rw-r--r-- 1 u0_a203 u0_a203 1687 Oct 25 15:35 termux.net_dists_stable_InRelease
-rw-r--r-- 1 u0_a203 u0_a203 14179 Nov 6 17:58 termux.net_dists_stable_main_binary-all_Packages
-rw-r--r-- 1 u0_a203 u0_a203 262594 Oct 25 15:35 termux.net_dists_stable_main_binary-arm_Packages
Previously the only difference with the 3rd and 5th entry was that they were owned by root:root, which I changed with chown. However I still was getting 'Permission Denied' if I tried to cat any of these 2 files. I also tried chmod 755, but reverted it when it didn't work.
The only thing I can think of is that I had to be a root user (via tsu) to run either chown or chmod. Could that be the problem?
@Monsieur-Moony
Yes These commands must be performed from the ROOT.
If you have only pkg problems, then delete it and refresh it again.
su -c rm /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_InRelease
apt update
@Deathlive Thanks, that solved the immediate issue. I was able to upgrade my packages :+1:
@fornwall Does Termux maintain its own state of a file outside of the file's inherent properties like ownership/permissions? I've been trying to understand why chown+chmod couldn't solve the 'Permission denied' errors alone. It would be helpful to know this because I still have some files which can only be worked with using a root user.
@Monsieur-Moony It's not Termux, it's SELinux. Here's how you can fix your files: https://wiki.termux.com/wiki/FAQ#I_updated_termux_packages_as_root_and_now_I.27m_getting_.27permission_denied.27_as_a_non-root_user.
@Neo-Oli Sorry, I forgot I had mentioned the issue here too. I actually wrote that entry in the FAQ (https://github.com/termux/termux-app/issues/335)
@Monsieur-Moony Ha! that's cool. :D
Estou tendo os mesmos problemas, e não sei como resolver, me ajudem
Most helpful comment
You should be really careful when running under root in Termux (and Android in general), this will break things such as apt and pip, and there is no point in doing so - you can install Termux packages fine without being root.
In the future we may add a warning to the
pkgcommand to avoid it being run as root by mistake, for now one just have to avoid it.