Running a Linux desktop on Android is a great way to get a portable development environment, test Linux tools, or simply enjoy a familiar desktop UI on your phone. The method described here uses Termux as the Linux base, proot‑distro to launch an Ubuntu rootfs, and XServer XSDL to provide an X11 display. All steps work on stock Android 9 – 13 without rooting.
If you have a custom ROM with heavy security restrictions (e.g., Samsung Knox), you may need to allow "Install unknown apps" for Termux and XServer XSDL.
Termux. Install the app.XServer XSDL. Install it. This app provides an X11 server that Termux can forward graphical output to./data/data/com.termux/files/usr/tmp/.X11-unix/X0) and ensures the app has the required overlay permission.Why these apps? Termux gives you a Linux terminal with its own package manager (pkg). XServer XSDL translates X11 drawing calls into a full‑screen Android window, letting you see a real desktop.
pkg update && pkg upgrade -ypkg install proot-distro wget curl git -ynano or vim for editing configuration files:
pkg install nano -yUpdating first prevents version mismatches later. proot-distro abstracts the complex proot command line and lets us manage multiple Linux distributions easily.
Proot‑distro supports several distros (Ubuntu, Debian, Alpine, Arch). Ubuntu provides a familiar desktop environment and a large repository, making it ideal for XFCE.
proot-distro listproot-distro install ubuntu-22.04~/.local/share/proot-distro/ubuntu-22.04. This may take a few minutes depending on your network.If the download fails due to a proxy or restricted network, you can manually download the rootfs tarball from the official Ubuntu mirrors and place it in the ~/.local/share/proot-distro folder, then run proot-distro install ubuntu-22.04 --file my‑ubuntu‑rootfs.tar.gz.
Ubuntu inside proot does not know about Android’s display. We need to tell it to forward X11 to the XServer XSDL instance.
DISPLAY=:0. Note the display number (usually :0).proot-distro login ubuntu-22.04127.0.0.1 (localhost) and the display number you saw earlier:
export DISPLAY=127.0.0.1:0xeyes (install first):
apt update && apt install x11-apps -y
xeyes
You should see a pair of eyes following your finger on the XServer XSDL window.If you see a blank screen, ensure that XServer XSDL’s permission to draw over other apps is still enabled. On Android 11+, you may need to go to Settings → Apps → XServer XSDL → Permissions and enable “Display over other apps”.
XFCE is lightweight, responsive on modest hardware, and works well with XServer XSDL’s virtual screen.
apt install xfce4 xfce4-terminal dbus-x11 -yapt install xinit -y.xinitrc file that launches XFCE when startx is called:
echo "exec startxfce4" > ~/.xinitrcstartx
The XFCE desktop should appear inside XServer XSDL. You’ll see a panel, a desktop background (plain gray by default), and the XFCE menu.Why startx and not a display manager? Android does not have a systemd init, so traditional display managers (gdm, lightdm) cannot run reliably. startx is a simple, script‑based way to launch the desktop.
Every time you power off the phone or close Termux, the Ubuntu instance stops. To make it convenient, we’ll create a small wrapper script that launches everything with a single command.
exit).run-ubuntu-xfce.sh in the Termux home directory:
cat > run-ubuntu-xfce.sh <<'EOF'
#!/data/data/com.termux/files/usr/bin/bash
# Start XServer XSDL if it is not already running
if ! pgrep -f "com.koushikdutta.xserver" > /dev/null; then
am start -n com.koushikdutta.xserver/.MainActivity &
sleep 2 # give XSDL time to initialise
fi
# Export DISPLAY to match XSDL's default
export DISPLAY=127.0.0.1:0
# Log into the Ubuntu distro and start the desktop
proot-distro login ubuntu-22.04 --shared-tmp -- bash -c "export DISPLAY=$DISPLAY; startx"
EOF
chmod +x run-ubuntu-xfce.sh./run-ubuntu-xfce.sh
The script will launch XServer XSDL (if needed), set the DISPLAY variable, and start XFCE inside Ubuntu.Note: The --shared-tmp flag makes the /tmp directory shared between Termux and the proot environment, which helps with clipboard sharing and temporary file handling.
While XServer XSDL handles graphics, you’ll still need a way to move files and copy text.
xclip inside Ubuntu:
apt install xclip -yxclip -selection clipboard -o to paste from Android’s clipboard into Linux, and xclip -selection clipboard -i to copy from Linux back to Android.~/storage directory can be linked inside Ubuntu. First, enable storage access in Termux:
termux-setup-storagemkdir -p /sdcard
mount -o bind /data/data/com.termux/files/home/storage/shared /sdcard/sdcard folder inside Ubuntu mirrors your Android internal storage, letting you open, edit, and save files directly.These bindings are temporary; to make them permanent, add the mount command to ~/.bashrc inside Ubuntu.
Running a desktop on a phone is inherently limited, but a few tweaks can improve responsiveness.
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile:1, export DISPLAY=127.0.0.1:1 instead.export DISPLAY line is executed inside the Ubuntu shell before launching any X program.gnome-terminal) require the dbus-x11 package. Install it if you see DBus‑related errors.proot, consider using the --link2symlink flag when launching the distro: proot-distro login ubuntu-22.04 --shared-tmp --link2symlink.termux-setup-storage again if needed).uid=1000,gid=1000 options to match the Ubuntu user ID.
mount -o bind,uid=1000,gid=1000 /data/data/com.termux/files/home/storage/shared /sdcardRunning a Linux environment on Android does not automatically harden your device. Keep these points in mind:
apt update && apt upgrade -y to receive security patches.Once you have a functional XFCE desktop, you can add many useful tools:
apt install build-essential git python3-pip for compiling code.apt install firefox (works, but may be heavy) or lightweight chromium-browser.code-oss (the open‑source VS Code) for a full‑featured editor.
apt install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/
sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
apt update && apt install code-oss -yopenssh-server and forward the port through Termux’s ssh command if you need to SSH into the Ubuntu instance from another device.These extensions turn your phone into a genuinely portable workstation.
By following the steps above you now have a fully functional Ubuntu XFCE desktop running on your Android phone, without needing root access. The environment is isolated, portable, and can be started with a single script. Use it for coding, lightweight server tasks, or just to explore Linux tools on the go.
Remember to keep both Termux and XServer XSDL updated via the Play Store or F‑Droid, and periodically refresh the Ubuntu packages. If you encounter any of the listed issues, revisit the troubleshooting section before reinstalling the whole stack.
Enjoy the freedom of a desktop Linux environment on a device that fits in your pocket!









