Skip to main content

How to use Termux X11 - The X server on Android phone

分類 Smartphone Termux Tutorial
標籤 Termux
Table of Contents

🇹🇼 中文版

Termux X11 is an app that can run X servers on Android phones. What does this mean? It means it can be used to execute Linux programs that rely on the X11 display, such as Firefox, Chromium, GIMP, Blender, Visual Studio Code, and more. Although Android is based on the Linux kernel, its graphics protocol differs from that used by most Linux distributions. Most Linux program toolkits are designed for X11 or Wayland, so Android cannot run Linux programs. Termux X11 provides an X server that runs on Android, allowing Termux’s Linux programs to display a graphical interface within it.

In addition, you can also achieve 3D hardware acceleration through the experimental VirGL server (virglrenderer) in Termux.

Termux X11 can be used with mouse and keyboard, or with touching gestures. Just setting the appropriate desktop resolution so you could interact with the desktop environment using your phone’s keyboard.

1. Install Termux X11
#

Termux X11 was inspired by Sparkle, and was initially implemented using XWayland, but was later replaced by XCB.

Currently, Termux X11 requires devices running Android 8 or later.

  1. Install Termux

  2. Download latest Termux-x11 APK from Github Releases. Download the Termux X11 APK.

  3. Install the Termux-x11 apk.

  4. Launch Termux, instal x11-repo. Then install termux-x11-nightly

pkg update

pkg upgrade

pkg install x11-repo

pkg install termux-x11-nightly

2. Usage 1: Run X11 apps in Termux
#

Personally, I recommended you to use Termux X11 with proot-distro because Termux has fewer package than proot-distros.

  1. Open Termux X11 APP and you will see this

  2. Go back to Termux. Install XFCE4 and GIMP

pkg install xfce gimp
  1. Launch XFCE4 with dbus-launch
termux-x11 :0 -xstartup "dbus-launch --exit-with-session xfce4-session"

If you encounter Make sure an X server isn't already running(EE) error, close Termux, then “Force stop” and “Clear cache” Termux and Termux X11 App in Android system settings.

  1. Now you should see XFCE4 runnning in Termux X11.

  2. You could change Touchscreen input mode in Termux X11 preferences in notification bar.

  3. If the font is too big, open System settings → Appearance → check Cutsom DPI. You can also set display resolution in Preferences of Termux X11 APP.

  4. Press CTRL+C in Termux to stop XFCE4.

3. Usage 2: Run X11 apps in Proot-distro
#

  1. Install a proot-distro. For example Debian proot or Arch Linux proot.

  2. Open Termux X11 app. Then go back to Termux.

  3. Log in to the installed Proot-distro using the regular account user. When logging in to proot here, you must add the --shared-tmp parameter, which means mounting the Termux $TMPDIR directory to the proot /tmp directory.

proot-distro login --user user debian --shared-tmp
  1. Launch desktop environment. For example, XFCE4
termux-x11 :0 -xstartup "dbus-launch --exit-with-session xfce4-session"
  1. While in Termux X11, you can activate phone keyboard by pressing back button. I suggest you to install Hacker’s Keyboard for using desktop shortcuts.

  2. Proot-distro have more packages than Termux. For an instance, it is possible to play Minecraft with MultiMC.

4. Usage 3: Run X11 apps in chroot
#

Root permission is required.

  1. Setup chroot Ubuntu

  2. Launch Termux X11 APP

  3. Go back to Termux, start Termux X11

termux-x11 :0 -ac &
  1. Mount Termux’s tmp to Ubunut’s tmp
sudo busybox mount --bind $PREFIX/tmp /data/local/tmp/ubuntu/tmp
  1. Log into chroot Ubuntu
sh /data/local/tmp/startu.sh
  1. Start XFCE4
sudo chmod -R 777 /tmp

export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1:4713

dbus-launch --exit-with-session startxfce4 &

5. Starting Wayland session in Termux
#

Termux-x11 is a X server. However it is possible to start a nested Wayland session in it.

Just intall weston and launch it in the terminal:

weston

6. GPU Acceleration in Termux X11
#

See: virglrenderer: Termux GPU Hardware Acceleration Tutorial

7. How to type Chinse in Termux X11
#

Go to Preferences → Keyboard, enable “Workaround to enable CJK Gboard”.

Press back button on your phone to activate Android’s soft keyboard.

Scroll the toolbar at the bottom to left and there will be a textbox for typing characters.

Related


此處提供二種留言板。點選按鈕,選擇您覺得方便的留言板。

(留言板載入中)這是Giscus留言板,需要Github帳號才能留言。支援Markdown語法,若要上傳圖片請善用外部圖床。您的留言會在Github Discussions向所有人公開。

Click here to edit your comments.

(留言板載入中)這是Disqus留言板,您可能會看到Disqus強制投放的廣告。為防止垃圾內容,有時留言可能會被系統判定需審核,導致延遲顯示,請見諒。若要上傳圖片請善用外部圖床網站。