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

🇹🇼 中文版

In this article I will tell you how to install proot Debian manually. This tutorial might also works for proot Ubuntu.

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 on-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

  1. Install Termux from F-Droid.

  2. Then setup Termux X11.

  3. Setup virglrenderer

2. Download Debian rootfs

  1. Install proot-distro and pulseaudio
1
2
3
pkg update
termux-setup-storage
pkg install proot-distro pulseaudio vim
  1. Edit .profile with VIM:
1
vim ~/.profile
  1. Download Debian rootfs using proot-distro
1
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.
1
proot-distro login debian --user root --shared-tmp
  1. Install sudo, vim, Firefox in proot
1
2
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
1
vim /etc/apt/sources.list
  1. Replace each line with new links(note currently the codename is bookworm):
1
2
3
4
5
6
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
1
apt update

4. Add a normal user

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

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

5. Install desktop environment

XFCE4 is a lightweight desktop environment.

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

1
apt install xfce4 xfce4-goodies

6. Setup locales

  1. Setup timezone. For example, Asia/Taipei.
1
ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
  1. Install locales
1
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
1
en_US.UTF-8 UTF-8
  1. Generating locales and set the language of system.
1
2
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.

1
2
3
4
5
6
7
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.
1
proot-distro login debian --user user --shared-tmp
  1. Start desktop environment
1
2
3
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)

1
2
mkdir .shortcuts
vim .shortcuts/startproot_debian.sh
  1. Type these
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#!/bin/bash

killall -9 termux-x11 Xwayland 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.
1
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 opened 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.

1
exit

References


Thanks for your reading. You are welcome to share articles of Ivon's Blog (ivonblog.com). Please include the original URL when reprinting or citing articles, and abide by CC BY-NC-ND 4.0 license. For commercial use, please write an e-mail to me.

written by human, not by AI

If this article is helpful to you please consider supporting me.

Leave a comment

Choose the commenting system you like.

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 some Disqus ADs on this page. You can leave a comment anonymously but you won't receive reply notifications.