Skip to main content

How to install proot Debian in Termux on Android phone (XFCE desktop + Audio + One-click starter)

Categories   Smartphone Termux Tutorial
Tags   Termux Debian
Table of Contents

🇹🇼 中文版

In this article I will tell you how to install proot Debian manually.

Step by step, I will install proot Debian from minimum rootfs provided by Temux maintainers and setup a XFCE desktop with audio. Root permission is not required. After setting up the system, I will tell you how to start dekstop environment in one-click, without typing commands in terminal.

The reason that I choose Debian over Ubuntu is Snaps. On Ubuntu 20.04 or higher, more and more packages will be redirected to install snap packages when running apt install commands, while snapd does not work on Termux proot. I would use a snap-free distro rather than disabling snapd on Ubuntu.

Note: If you don’t want to install everything step by step, use automated scripts made by Termux community instead.

1. Prerequisites
#

RAM >= 6GB

Storage > 10GB

My Device: Xiaomi Poco F1, Lineage OS 20 (Android 13)

  1. Install Termux from F-Droid.

  2. Then setup Termux X11.

  3. Setup virglrenderer

2. Download Debian rootfs
#

  1. Install proot-distro and pulseaudio
pkg update
termux-setup-storage
pkg install proot-distro pulseaudio vim
  1. Edit .profile with VIM:
vim ~/.profile
  1. Download Debian rootfs using proot-distro
proot-distro install debian
  1. Log into Debian proot. --user will make you directly login to the specific user (only root available in the fresh installation). --shared-tmp will mount Termux’s tmp directory in proot.
proot-distro login debian --user root --shared-tmp
  1. Install sudo, vim, Firefox in proot
apt update
apt install sudo vim firefox-esr

3. Change Debian mirrors
#

(Optional) This would make APT downlaoading faster.

See SourcesList - Debian Wiki

Find mirrors on Debian mirrors

  1. Edit sources.list
vim /etc/apt/sources.list
  1. Replace each line with new links(note currently the codename is bookworm)
deb http://opensource.nchc.org.tw/debian/ bookworm main contrib non-free
deb-src http://opensource.nchc.org.tw/debian/ bookworm main contrib non-free
deb http://opensource.nchc.org.tw/debian/ bookworm-updates main
deb-src http://opensource.nchc.org.tw/debian/ bookworm-updates main
deb http://security.debian.org/debian-security bookworm/updates main contrib non-free
deb http://opensource.nchc.org.tw/debian bookworm-backports main
  1. Refresh packages list
apt update

4. Add a regular user
#

It is recommended to create a regular user for your security. Don’t do everything in root.

  1. Change root password
passwd
  1. Add group “wheel” and “video”
groupadd storage
groupadd wheel
groupadd video
  1. Add new regular user named “user” and change his password
useradd -m -g users -G wheel,audio,video,storage -s /bin/bash user
passwd user
  1. We need to add regular users to sudoers. Type visudo then find something like root ALL=(ALL:ALL) ALL. Add this in the next line of it.
user ALL=(ALL:ALL) ALL
  1. Switch to user
su user
cd

5. Install desktop environment
#

GNOME (package name:gnome) may not work in proot. And KDE (kde-full) is too heavy for smartphone.

Therefore, I choose XFCE4, a lightweight desktop environment.

Install XFCE4 desktop environment. Type “0” when apt asking for the keyboard layout.

apt install xfce4 xfce4-goodies dbus-x11

6. Setup locales
#

  1. Setup timezone. For example, Asia/Taipei.
ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
  1. Install locales
apt install locales fonts-noto-cjk
  1. Edit /etc/locale.gen with vim: vim /etc/locale.gen. Uncomment (remove “#”) your langauge. For example en_US.UTF-8
en_US.UTF-8 UTF-8
  1. Generating locales and set the language of system.
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf

7. Start desktop environment (manually)
#

  1. Relaunch Termux

  2. Launch Termux X11 app, keep it opening in the background. Go back to Termux and type the following commands to run Termux X11.

pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1
pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1

export DISPLAY=:0
termux-x11 :0 &

virgl_test_server_android &
  1. Log into Debian as user.
proot-distro login debian --user user --shared-tmp
  1. Start desktop environment
export DISPLAY=:0
PULSE_SERVER=tcp:127.0.0.1
dbus-launch --exit-with-session startxfce4 &
  1. You shall see XFCE4 desktop showing at Termux X11. Tap flaoting window and revoke permission to make it go full screen.

8. Start desktop environment in one-click
#

We can use Termux Widget to start everything automatically. Thanks to Korean developers from clien.net!

  1. Install Termux API and Termux Widget

  2. Go to system settings → all apps, turn on “Permit Drawing Over Other Apps” for Termux.

  3. Restart Termux. Create a shortcut in Termux (not in proot-distro)

mkdir .shortcuts
vim .shortcuts/startproot_debian.sh
  1. Type these
#!/bin/bash

killall -9 termux-x11 pulseaudio virgl_test_server_android termux-wake-lock

termux-toast "Starting X11"
am start --user 0 -n com.termux.x11/com.termux.x11.MainActivity
XDG_RUNTIME_DIR=${TMPDIR}
termux-x11 :0 -ac &
sleep 3

pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1
pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1

virgl_test_server_android &

proot-distro login debian --user user --shared-tmp -- bash -c "export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1; dbus-launch --exit-with-session startxfce4"
  1. Make it executable.
chmod +x .shortcuts/startproot_debian.sh
  1. Go to your home screen, long press and add widgets → select “Termux Widget”. You would see the shortcut we made is on the list.

  2. Click “startproot_debian.sh” then the XFCE desktop would start automatically.

  3. Swipe down the notification bar, click Preferences of Termux X11. Then you can switch touch screen mode to simulating touchpad.

  4. To use soft keyboard of phone in Termux X11, swipe the bar at the bottom and you will see a field for inputing texts.

  5. If the fonts are too small in Termux X11, click Settings Manager at top-left → Appearance and change font size or select 2x window scaling.

  6. To stop the XFCE session, press CTRL+C in Termux. Then logout of proot Debian.

exit

References
#

Related

Installing Anaconda on Android (aarch64) devices
Categories   Smartphone Termux Tutorial
Tags   Termux
How to run Stable Diffusion on Termux on Android phone
Categories   Smartphone Termux Tutorial
Tags   Stable Diffusion AI Android Termux
How to play Minecraft Java Edition on Android using Termux proot
Categories   Smartphone Termux Tutorial
Tags   Raspberry Pi Minecraft Termux

Leave a comment

Choose the comment system you like. Giscus for codes, Disqus for anonymous comments.

Please login to your Github account to leave a comment. You can post codes here for discussion. For images, please upload to Imgur and copy links. Your comments would be visible to everyone on Github Discussions.

This comment system is provided by Disqus, you may see forcing Disqus ADs on this page. Sometimes your comment may need to be reviewed, resulting in delayed display. Thank you for your understanding.