Loading Blog Search...

Saturday, February 15, 2025

Development with Linux Terminal on Pixel Tablet

Android is transforming to a cross tablet and desktop OS. Google is officially supporting Linux installation on Android 15/16 beta versions!  This Linux distribution uses Android's AVF framework, making it feel like native Linux on your device.  While there were still some bugs as of February 2025, it's become quite usable, especially on Google Pixel Tablets.  For me, it's perfect for light development work and trying out new code while traveling.  Here's how I set up my development environment on my 11-inch tablet.

Enable Linux Terminal

Enable developer mode and Linux development environment. After enabling it, look for new Terminal app in your app list. There is no need to goto Play store to install it. If you disabled the option, the Linux Terminal app will be automatically removed and all data in the Linux instance will be deleted. 




Install Debian (Ubuntu?)

When the terminal app starts, it will prompt to enable notification. My install was failed when I rejected it at Android 15 beta. At right bottom there is a button to start install of Linux. Click it to download a 600MB size Debian distribution. Currently Google dev team is fixing bugs and patching the distribution without formal announcement. You can reinstall latest version by disabling and re-enabling Linux development environment. Backup before do it.

After installing, the Debian starts and print:
Linux localhost 6.1.0-29-avf-arm64 #1 SMP Ubuntu 6.1.123-1 (2025-01-02) aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.

    

Enable testing channel


    $ sudo vim /etc/apt/sources.list # add the line, change to mirror nearer to you
    deb https://mirror.coganng.com/debian/ testing non-free non-free-firmware contrib main
    $ sudo apt dist-upgrade
    $ sudo reboot

This step is important, as port forwarding didn't work without testing channel for me.

Install Openssh server

Current Linux terminal uses WebView to display the Linux terminal, and keeps disconnecting and reconnecting, so that it's not very useful to use it before it get stabler. We can workaround though by connect to it via SSH with a stable Android SSH client.

    $ sudo apt update
    $ sudo apt install openssh-server
    # Edit /etc/ssh/sshd_config to change Port to '5900'
    # default port '22' doesn't work.
    $ sudo systemctl enable ssh # start ssh server after bootup
    $ sudo passwd droid # change password for SSH client to use
After ssh service starts, a popup will prompt to accept port forwarding to port 5900. This popup is added at Android 16 beta2. We can check the ports enabled at Linux terminal setting. Enter setting page by clicking the gear button at top right corner of Linux terminal app.


Install GUI apps and VNC

 X


    $ sudo apt install xfce4
    $ sudo update-alternatives --config x-session-manager
    $ sudo apt install tigervnc-standalone-server 
    $ tigervncserver -localhost :3 -geometry 2560x1600
    $ tigervncserver -kill :3 # stop vnc

Swap memory

In beta Linux Terminal crashes often when memory use exceed 4GB. We need to add more swap memory. Also crashes reduced by updating grub to limit physical memory to 3650m, by adding “mem=3700m”. This works better than tunning Linux oom killer, e.g.,  vm.overcommit_memory so far.


$ sudo fallocate -l 3G /swap
$ sudo chmod 600 /swap
$ sudo mkswap /swap
$ sudo swapon /swap
$ sudo swapon -s #update /etc/fstab for defaults mount on boot

Install Termius

X and GUI apps takes large space while max space Linux Terminal could allocate is 15GB. Sticking with text mode may not be a bad idea, especially for developers who are used to NeoVim. 

As we have turned on SSH service, a SSH client is required. I have tried termux, JuiceSSH and Termius. Termius is kept as its default font works best when I use neovim IDE which needs font icons in the IDE. Setup a SSH connection to ssh://droid@localhost:5900 with the password set in previous step. After ssh to the SSH service, the Linux environment is working quite stable. And we can setup dev environment with usual steps for Debian/Ubuntu.

Dev at Text mode with NeoVim

NeoVim is a powerful text mode IDE while the UX is so well designed that I don't feel much difference from using VSCode. Can refer to articles online to setup it up quickly using nvChad like https://blog.spoonconsulting.com/getting-started-with-neovim-using-nvchad-a-developers-guide-f97d81e85d60 

NeoVim Cheatsheet

1. space+c h: cheatsheet
2. ctl-n: show file explorer. 'g?' shows what can be done in explorer. 
3. space+h: show terminal at bottom. In terminal, if mouse click it will go into 'EDIT' mode, and show 'NTERMINAL' at left-bottom. In EDIT mode, can't execute cmds or use key like ctl+c. In this case, type 'i' will make it go back to terminal mode.
4. space+f f: search file by name
5. space+f w: search in files
6. space+t h: select theme
7. ZZ: exit

Remote access to Services running in Linux Terminal

Install a port forwarder like: https://play.google.com/store/apps/details?id=com.gorillasoftware.portforwarder 


With the sample config, we now are able to SSH to the yourAndroidIP from a remote machine, e.g., my tahlet IP is 192.168.1.54.

    
    $ ssh droid@{yourAndroidIP} -p 5800

Docker Install

Docker works well so far, following apt method at https://docs.docker.com/engine/install/debian/,  but change its source list distribution from trixie in /etc/os-release to bookworm.

Chromium Sync to Chrome

Didn't get time to try, bookmarked https://www.learningtopi.com/sbc/chromium-sync/




No comments: