Exiting Vim On A Touch Screen, The New Development Environment Frontier
So you finally figured out how to exit Vim and you can write the most highly optimized version of “Hello World” this side of the Mississippi. Now it’s time to up your game! Checkout Termux for Android.
What is Termux?
Termux is an Android terminal emulator and Linux environment. What that means in practice is that you can install Termux on most Android devices and do almost anything you would do in a full Linux development environment on that device.
Why use Termux?
If you’re like most people, you are thinking why would I want to develop on my phone?! Maybe you’re in a pinch and you only have your phone at the moment to fix something? But probably more likely, maybe you want to develop on a tablet or Chromebook. Termux can help in any of those situations.
Sound interesting? The following are some tips to help set up your Termux development environment. While Termux is a full Linux environment, it functions slightly different than other Linux environments, and you’ll probably run into some roadblocks.
Where’s All My Stuff?
Because Termux is an isolated version of Android Linux, typical Linux file structures do not apply and you do not have root access. While the Termux developers have adjusted their package system for this, when you install things from other sources, this can be a problem. Bash, for example, is typically located at
/bin/bash. And in practice almost every Bash script on the planet is hard-coded to this path. Termux provides a package to help fix this called termux-exec. However, you still may have some path problems. I typically go for the chroot solution instead. Chroots let you make an isolated version on the OS which you can now have more control over. Use this script by Neo-Oli to set up your chroot. Once you’re in your chroot, you can install termux-exec and create symbolic links to fake a typical Linux structure.
Because Termux is Android Linux, it is missing some typical Linux things that you may need to find alternatives for. Not much advice here, other than to be prepared. As a Python developer, I ran into the issue of semaphore facilities not being included in Android. This is used by Python to implement multiprocessing, and a lot of Python multiprocessing libraries depend on this. However, there are alternative ways to do multiprocessing. In practice, that meant I had to switch my Python web development to use
Gunicorn instead of
uWsgi. You can also get around this by making sure to skip installation of the multiprocessing packages that may only be needed on a production system.
Starting and Stopping Services
Most of your typical services are available to install like nginx, Postgres, MariaDB, Redis, Memcache, etc; however, since you don’t use Termux as root, you will need to remember to start and stop these services manually. Here are a few commands I’ve learned recently and aggregated into start and stop scripts.
- Postgres Start:
pg_ctl -D $PREFIX/var/lib/postgresql
- Postgres Stop:
pg_ctl -D $PREFIX/var/lib/postgresql stop
- Nginx Start:
- Nginx Stop:
nginx -s stop
- Redis Start:
- Redis Stop:
redis-server "$("$PREFIX/bin/applets/cat" /var/run/redis_6379.pid)"
This doesn’t cover all Linux services, but hopefully it gives you a good sense of the patterns you’ll need to know to write your own start and stop scripts.
With these tips and tricks I’ve been able to set up a productive Chromebook web development environment. Termux might not be for you, but it’s fun to explore different environments at the very least to teach you more about Linux.