Skip to main content

How to install proot Ubuntu in Termux on Android phone (Desktop + Audio + One-click starter)

Categories   Smartphone Termux Tutorial
Tags   Termux Ubuntu
Table of Contents

🇹🇼 中文版

This article introduces how to install Ubuntu with desktop environment on Android mobile phones without Root permissions.

Ubuntu + KDE Plasma on Android

We will use the proot-distro provided by Termux to manually create the Ubuntu desktop environment. After everything is ready, we will setup a one-click startup script at the end of the article.

If you don’t want to manually configure Ubuntu, please use the community scripts to install it automatically.

1. Prerequisites
#

Your phone needs at least 6GB of RAM to run the Ubuntu desktop environment.

The processor is recommended to be Qualcomm Snapdragon 845 or above.

Storage space must be at least 10GB.

My device: Sony Xperia 10 V, Android 13

  1. Install Termux

  2. Install Termux X11

  3. Set up GPU hardware acceleration virglrenderer

2. Install Ubuntu minimal file system
#

The minimal file system here refers to the rootfs provided by the maintainer of proot-distro. The rootfs they maintain does not have an LTS version and is always the latest version of Ubuntu of the year.

  1. Open Termux and install Proot-distro and PulseAudio
pkg update
termux-setup-storage
pkg install proot-distro pulseaudio vim
  1. Install root Ubuntu
proot-distro install ubuntu
  1. Log in to Ubuntu. The --user parameter indicates logging in as root. --shared-tmp mounts the Termux tmp directory into proot so that X server resources can be shared later.
proot-distro login ubuntu --user root --shared-tmp
  1. After logging in, install sudo, vim, and PPA tools. It may ask for your time zone during installation, enter a number to answer.
apt update
apt install sudo vim software-properties-common
  1. Because Android does not have Systemd, please enter the following command to disable Ubuntu’s Snap
cat <<EOF | sudo tee /etc/apt/preferences.d/nosnap.pref
# To prevent repository packages from triggering the installation of Snap,
# this file forbids snapd from being installed by APT.
# For more information: https://linuxmint-user-guide.readthedocs.io/en/latest/snap.html
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOF
  1. Then install Firefox through Mozilla’s ppa:
sudo add-apt-repository ppa:mozillateam/ppa
sudo apt-get update
sudo apt-get install firefox-esr
  1. To exit the proot, enter exit to log out.

3. Change mirrors
#

This is an optional step. Changing mirrors can speed up package downloads.

For a list of global mirrors, please see Official Archive Mirrors for Ubuntu

  1. For example, use the following command to replace all the ports.ubuntu.com URLs in /etc/apt/sources.list with the URL of the NCHC, Taiwan:
sudo sed -i 's/ports.ubuntu.com/free.nchc.org.tw/g' /etc/apt/sources.list
  1. Update the package list again
apt update

4. Create a regular user
#

Usually we do not use the root acount operating system. For this purpose, we need to create a regular user account and add the sudo command to temporarily increase the permissions when the system needs to be changed (such as executing the apt command).

  1. Change root password
passwd
  1. Added wheel and video groups
groupadd storage
groupadd wheel
groupadd video
  1. Add a new regular account “user” and change the password.
useradd -m -g users -G wheel,audio,video,storage -s /bin/bash user
passwd user
  1. Add user to the sudo group. Execute the visudo command, find root ALL=(ALL:ALL) ALL, and add the following content to the next line:
user ALL=(ALL:ALL) ALL
  1. Switch to the regular user
su user
cd

5. Install desktop environment
#

If you konw how to use the text-only interface, you don’t need to install the desktop environment.

As for the choice of desktop environment, choose one of the three.

XFCE
#

  1. Install XFCE (Xubuntu configuration).
sudo apt install xubuntu-desktop
  1. Set the default terminal emulator and enter the number of xfce4-terminal
sudo update-alternatives --config x-terminal-emulator

The command to start with dbus is startxfce4. This will be discussed below.

KDE
#

  1. Install KDE (Kubuntu configuration)
sudo apt install kubuntu-desktop
  1. Set the default terminal emulator and enter the number of konsole
sudo update-alternatives --config x-terminal-emulator

The command to start KDE with dbus is startplasma-x11. This will be discussed below.

GNOME (experimental)
#

Install GNOME

sudo apt install ubuntu-desktop

The command to start GNOME is export XDG_CURRENT_DIR=GNOME && service dbus start && gnome-shell --x11

6. Set time zone, language, input method
#

  1. Set the time zone, for exmaple, to Taipei, Taiwan
sudo ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
  1. Install locales
sudo apt install locales fonts-noto-cjk
  1. Edit: vim /etc/locale.gen, find your language, and remove the previous annotation (#):
en_US.UTF-8 UTF-8
  1. Generate the language
locale-gen
echo "LANG=en_US.UTF-8 UTF-8" > /etc/locale.conf
  1. Use VIM to edit .profile
vim ~/.profile
  1. Add the following content at the end of the file, set the language to en_US.UTF-8
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=

7. Set up a one-click startup desktop environment script
#

Here we will set up shortcuts to start Termux, Termux X11, virglserver with one click to automatically start the desktop environment.

  1. Exit the proot environment and exit Termux
exit
exit
exit
  1. Install Termux Widget

  2. Open the phone system settings and enable the “Allow display on top of other applications” permission for Termux.

  3. Restart Termux and enter the following command to create a shortcut

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

# Kill 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 GPU accelerated virglserver
virgl_test_server_android &

# Log in to proot Ubuntu and start the desktop environment. Note that startxfce4 at the end is used to start the XFCE4 desktop.
proot-distro login ubuntu --user user --shared-tmp -- bash -c "export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1; dbus-launch --exit-with-session startxfce4"
  1. Grant execution permissions
chmod +x .shortcuts/startproot_ubuntu.sh
  1. Go to your phone’s desktop, add a new widget → select Termux Widget, and you will see the shortcut you just wrote appear in the list.

  2. Click the button and Termux will automatically open the login desktop.

  3. Pressing the back button in the Termux X11 interface will wake up the mobile phone keyboard. Here I recommend using Hacker’s Keyboard for easy operation of Ubuntu.

  4. Slide down the notification bar of your phone and click Preferences of Termux X11 to change the touch control to simulate a trackpad, so that you can use the emulated mouse to interact with the desktop.

  5. The desktop icon may be a bit too small. Change the Display resolution mode to Scaled and scale it according to your preference.

  6. It is also recommended to disable the screen lock and screen saver in the Linux system settings, because in proot it cannot unlock the screen saver.

  7. To terminate the execution of Ubuntu, press Exit on the notification bar of your phone to exit. Then force stop Termux and Termux X11 apps.

Further reading
#

Related

[Root] Install Ubuntu in chroot on Android without Linux Deploy
Categories   Smartphone Termux Tutorial
Tags   Linux Android Ubuntu Termux
How to install proot Debian in Termux on Android phone (XFCE desktop + Audio + One-click starter)
Categories   Smartphone Termux Tutorial
Tags   Termux Debian
How to install Arch Linux ARM on Android phone (Termux Proot-distro)
Categories   Smartphone Termux Tutorial
Tags   Arch Linux 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.