03 December 2019

How to Use the Linux Command Line on Android With Termux


Android is a capable operating system, as it offers many apps that approach desktop class. Yet sometimes, it takes a fair bit of effort to accomplish something on Android that would be a snap on a desktop.

One solution is to take advantage of Android’s hidden Linux infrastructure. The Termux app provides a command line environment and allows you to install honest-to-goodness Linux apps on your Android device. Here’s how to use the Termux app.

Why Use Termux?

There are already some apps in the Play Store that are Android ports of Linux applications. These differ from Termux in that they replicate those Linux apps, but they’re made in an “Android way.”

In contrast, Termux is a self-contained Linux environment. Its programs are (for all intents and purposes) the same as their Linux counterparts. This conveys some advantages over the ported applications:

  • Consistency: Linux apps that have been ported to Android require a user interface of some kind. The user experience on Android largely depends on how much effort the developer puts into it. Conversely, Termux apps are the same as the Linux versions, from keyboard shortcuts to how you install them.
  • Compactness: The addition of Android code can cause some slim applications to become heavy. For example, an Android SSH client might be anywhere from 2MB to 12MB in size. Compare this to Dropbear, available in Termux, which weighs in at 396KB (that’s kilobytes) installed. And it provides an SSH server too.

Get a Linux command line on Android with Termux

  • Timeliness: When an application receives an update, you remain at the mercy of the Android app’s developer for an upgrade. In contrast, Termux applications are standard Linux packages that require less maintenance. They may even be created automatically alongside the desktop versions. You’re likely to get access to new features more quickly with Termux.
  • Price: There is a chance any app you purchase from the Play Store will have a charge associated with it. All the apps in Termux are free (and open source), as is Termux itself.

How to Use Termux

Before diving in, understand that Termux is primarily a command line environment. There’s no fancy user interface with shiny buttons here. This goes not only for the base Termux package, but its apps as well. You won’t get the newest version of LibreOffice with this method.

Most importantly, you must be comfortable with the command line in order to install and use these programs on Termux. To develop some familiarity, check our list of the most-used Linux Terminal commands.

When you’re ready, grab your phone or tablet and install Termux.

Download: Termux (Free)

Basic Termux Commands You Should Know

Launching Termux will drop you straight into a command line environment. From here, you can install new tools. Termux uses the same package installer as found in Debian, Ubuntu, and related Linux distros.

Advanced Packaging Tools (more commonly referred to as APT) is used to find, install, and remove software in Termux. Start off by updating packages and upgrading with these commands:

apt update

apt upgrade

Update packages in the Termux command line

Next, find out what apps are available:

apt list

To find out more about one of these packages, use

apt show [package name]

This will display the name, maintainer, file size, dependencies, and other useful details. To install an app, simply use:

apt install [package name]

Our guide to using APT will tell you more about this tool, such as how to upgrade packages. You can run an installed tool by entering its name at the Terminal prompt in the Termux command line.

In addition to apt, this list of built-in commands works in Termux on Android:

  • cp lets you copy a file
  • mv will move a file
  • ls lists the contents of a directory
  • rm deletes (removes) data
  • ln creates a symbolic link (for example, ln /data/data/com.termux/files/home/documents to /sdcard/Documents)

With these built-in tools, you reduce the need for an Android file manager. They also save you from having to root your phone to enjoy such functionality.

Linux Apps You Can Install With the Termux Command Line

Using apt with Termux, you can install several useful Linux apps on Android. These fall into several categories—let’s look at some of the highlights.

Text Editors

Termux provides recent versions of both popular Linux text editors: VIM and Emacs. Other editors, such as the minimalist nano, are also available.

Of course, Android has a lot of text editors already. So what do Emacs and Vim bring to the platform? Well, if you like to work in Markdown, both support it well. Into the “distraction-free” mindset? It doesn’t get much more distraction-free than VIM.

Need something to take notes and provide to-dos? Org-mode in Emacs has you covered. You can even use Emacs as your file manager, screenwriting app, Trello client, music player, or to play Minesweeper.

Why switch? Android text editors tend to focus on one standout feature. For example, one may focus on distraction-free drafting, another can preview Markdown and other formatting, and still others might be built on keeping notes (though they’re really just text editors at their core).

Terminal-based editors can fulfill these needs in a single program, while also being available on desktop platforms.

Termux Command Line Utilities

Termux packages include several useful Linux command line utilities:

  • gnuplot: A mathematical graphing program
  • ImageMagick: An image manipulation and conversion toolkit
  • p7zip: An archiving utility for the 7-Zip compression scheme
  • UnRAR: A different archive tool for the RAR format
  • Wget: A program to fetch files over the internet via HTTP or FTP

Why switch? These are dedicated programs with a lot to offer.

Install Servers in Termux

We’ve already shown how you can turn your Android device into a web server with specific apps. Termux similarly provides genuine Linux web servers like Apache, nginx, and Lighttpd.

But why would you want to run a web server on your Android device?

In addition to programming, bear in mind that many of today’s best applications are web apps. For example, you could install nginx, the PostgreSQL database, and Python, then use the Taiga project management platform. This is a lot of utility, all without having to sign up for any third-party services or hosting.

Termux also includes Dropbear, which provides an SSH server (and client) to log into your phone/tablet and transfer files. This is useful in situations where you want to exchange a few files but don’t want to use cloud services. Simply start up the Dropbear server, use an SSH client to grab what you need, and shut it down.

Why switch? Apps like Tiny Web Server allow you to spin up a web server. But what’s more intriguing than having a lightweight server you can start from the command line?

Development Apps in the Termux Command Line

While many Android apps (listed as “code editors”) provide the ability to write code, they may not provide the languages themselves. With Termux, you can test your code on your phone or tablet.

Install Python development tools in the Termux command line

It offers standard distributions of programming languages such as:

  • BASH shell (the default available out of the box, and a great way to get started hacking around)
  • Python (both v2 and v3 are available)
  • PHP
  • Ruby

Source control systems git and Subversion are also available, which have their uses beyond just development. If you like being in control of your own data, source control lets you stash your files wherever you want. You also control when you send updates to other devices, and can use “tags” to label versions.

Why switch? There are some programming language packages for Android, such QPython. But these provide their own bulky UIs. They may also require additional apps to be fully useful.

Android-based apps are available for both git and svn. However, you need to have a separate app for each source control type. Termux provides both in the same package for free. By going with source control, you can also cut down on clients for cloud syncing services such as Dropbox.

Add Linux to Android With Termux Commands

Termux is a super-compact offering that opens a lot of functionality for your Android device. The command line is one of the most powerful features of Linux, and Termux builds on your device’s Linux kernel to make you more efficient on the go.

And who knows, maybe dabbling with these apps will convince you to try Linux on the desktop as well. Check out our Linux commands cheat sheet for some help giving it a try.

Read the full article: How to Use the Linux Command Line on Android With Termux


Read Full Article

No comments:

Post a Comment