Skip to main content

Install a graphical desktop environment and audio output in Termux

·
Categories Smartphones Termux Tutorials
Tags X Window VNC
Table of Contents

Note: because the Termux filesystem differs from ordinary Linux and has fewer packages, I tend to install a Linux proot container and run the desktop environment there. Although it is slower, the experience is better.

By default, Termux only has a text interface. Users can install a desktop environment themselves, then connect through VNC or Termux X11 to get a desktop-computer-like experience.

At present, desktop environments included in the Termux package repository include XFCE, LXQT, MATE, OpenBox, i3wm, Weston, and so on.

Termux can also use Android GELS to output audio, so we can run a PulseAudio server for audio output in the desktop environment.

This article explains how to install the XFCE desktop and configure the PulseAudio server.

Termux running the XFCE desktop environment and desktop Firefox browser

1. Prerequisites
#

To run a desktop environment, I recommend a phone with at least 6GB RAM.

Please install Termux first, and remember to disable Phantom Process Killing to prevent Termux from being terminated by the system in the background.

2. Install the XFCE desktop environment
#

Termux does not package many desktop environments, so choose XFCE, which is lightweight but still sufficiently functional.

Install XFCE4, the Firefox browser, and the VIM editor:

pkg install x11-repo

pkg install xfce xfce4-goodies pulseaudio pavucontrol vim firefox

3. Connect to the graphical interface
#

Choose one of the two; they can coexist. I recommend Termux X11, which performs better than VNC, but is less convenient for remote connections.

Termux X11
#

  1. Configure Termux X11 and virglrenderer.

  2. To make starting the desktop environment easier later, add a script

vim ~/startxfce4.sh
  1. Fill in the following content:
#!/bin/bash

# Start GPU acceleration
virgl_test_server_android &

# Start audio server
pulseaudio --start --exit-idle-time=-1
pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1

# Start desktop environment
termux-x11 :0 -xstartup "dbus-launch --exit-with-session xfce4-session" &
  1. Grant execute permission
chmod +x ~/startxfce4.sh
  1. Exit Termux.
exit
  1. Start the Termux X11 app

  2. Return to Termux and start the desktop environment. The XFCE4 desktop will appear in the Termux X11 app screen.

./startxfce4.sh

VNC server
#

  1. Install the AVNC client on the phone

  2. Install the TigerVNC package. The current version is 1.13.0.

pkg install tigervnc
  1. Set the VNC server password
vncpasswd
  1. Add the program to execute after the VNC server starts by editing ~/.vnc/xstartup
mkdir ~/.vnc/

vim ~/.vnc/xstartup
  1. Fill in the following content
#!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADRESS

# Start the PulseAudio sound server; audio will come out from Termux
pulseaudio --start --exit-idle-time=-1
pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1

# Run the desktop environment, XFCE here
exec startxfce4
  1. Grant execute permission to xstartup
chmod +x ~/.vnc/xstartup
  1. Define the VNC server configuration file. Edit ~/.vnc/tigervnc.conf
vim ~/.vnc/tigervnc.conf
  1. Fill in the following content:
# Current session XFCE
$session="xfce-session";
# Resolution; higher values use more bandwidth
$geometry="1920x1080";
# Bit depth, values are 8/16/24/32; larger numbers look better but use more bandwidth
$depth="32";
# Allow external networks to connect
$localhost="no";
  1. Enter the tigervncserver or vncserver command in Termux to start the VNC server. Observe the port number output on the screen; it usually starts from 1. Since VNC server ports count from 5900, the port here is 5901.

  2. Open the AVNC app, add a host connection, enter localhost for the address, and 5901 for the port.

4. One-click desktop environment startup script
#

Typing commands every time you start the desktop environment is too troublesome. Use a Termux Widget desktop shortcut to run the startup process for Termux + Termux X11 + virglserver with one click, automatically starting the desktop environment.

  1. Install Termux Widget

  2. Open system settings and grant Termux the “allow display over other apps” permission

  3. Reopen Termux and enter the following commands to create a shortcut

mkdir .shortcuts

vim .shortcuts/start_xfce.sh
  1. Fill in the following content
#!/bin/bash

# Terminate all old processes
killall -9 termux-x11 pulseaudio virgl_test_server_android termux-wake-lock

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

# Start PulseAudio
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

# Start the GPU-accelerated virglserver
virgl_test_server_android &

# Start the XFCE4 desktop environment
export DISPLAY=:0
export PULSE_SERVER=tcp:127.0.0.1
dbus-launch --exit-with-session startxfce4 &
  1. Grant execute permission
chmod +x .shortcuts/start_xfce.sh
  1. Go to the phone home screen, add a widget -> select Termux Widget, and you will see the shortcut you just wrote appear in the list.

  2. Tap the button, and Termux will automatically open and log in to the desktop.

Related


Thank you for reading. Public comments are not available on this website. I write to explore ideas honestly, not to chase social engagement or traffic. I would be glad to hear your thoughts after reading the article with care. If you found any errors, technical issues, or would like to share feedback, feel free to contact me via the email listed on the About page.