Skip to content

Getting Started with Termux: A Beginner’s Guide

Termux is a powerful terminal emulator for Android that allows you to run a full Linux distribution on your mobile device. It provides access to a command-line environment where you can install and use a variety of Unix/Linux utilities and tools. Whether you’re a developer, a sysadmin, or just a curious tech enthusiast, Termux offers a way to unlock the full potential of your Android device, allowing you to run everything from basic shell commands to full-fledged development environments. This guide will walk you through the steps of setting up Termux on your Android device, provide an overview of its key features, and explain how you can use it to perform various tasks. By the end of this guide, you’ll have a solid foundation in using Termux to boost your productivity and manage your Android device more effectively.

What is Termux?

Termux is more than just a terminal emulator; it is a Linux environment built specifically for Android. It gives you access to a powerful shell and the ability to install a range of packages using the APT (Advanced Package Tool) package manager. With Termux, you can use your Android device to run a variety of Linux tools, including programming languages like Python, C, and Ruby, text editors like Vim and Emacs, and many networking and system administration utilities. Termux doesn’t require root access, which makes it an attractive option for users who want to work on their device without modifying its underlying system. It’s simple to set up and lightweight, which means you can run it on most Android devices without slowing down your system.

Installing Termux

Before diving into Termux’s functionality, let’s start by installing it on your Android device.
  1. Open Google Play Store (or F-Droid): Termux can be installed directly from the Google Play Store or F-Droid. While the Google Play Store version is convenient, it might not always have the latest features due to the way updates are handled. For the latest updates, it’s recommended to download Termux from F-Droid.
  2. Search for Termux: In the Google Play Store or F-Droid, search for “Termux.” Click on the Termux icon to view the app details.
  3. Install the App: Click on the “Install” button. The installation process will take a few moments.
  4. Launch Termux: Once installed, open Termux from your app drawer. You will be greeted by a command line interface (CLI).

Basic Commands in Termux

When you open Termux, you’ll see a terminal screen where you can type commands. Here are some essential commands to get you started:
  • pwd: This command prints the current working directory. It helps you know where you are in the file system.
pwd
  • ls: The ls command lists files and directories in the current directory.
  • ls
  • cd: Change directories. You can navigate through the file system by using the cd command.
  • cd /storage/emulated/0
  • mkdir: Create a new directory.
  • mkdir my_directory
  • touch: Create an empty file.
  • touch myfile.txt
  • cat: Display the contents of a file.
  • cat myfile.txt
  • cp: Copy files or directories.
  • cp file1.txt file2.txt
  • mv: Move or rename files or directories.
  • mv file1.txt file2.txt
  • rm: Delete a file.
  • rm file1.txt
  • exit: Exit the Termux session.
  • exit

    Updating and Installing Packages

    Termux relies on APT (Advanced Package Tool) to install and manage software packages. The first thing you should do after installing Termux is update the package repositories to ensure you have access to the latest software.
    1. Update Package Repositories: To update the package repositories, type the following command:
    2. pkg update
    3. Install Packages: You can install various software packages using the pkg install command. Here are a few examples:
    • Install Python:
      pkg install python
    • Install Git:
      pkg install git
    • Install Vim:
      pkg install vim
    • Install curl:
      pkg install curl
  • Upgrading Installed Packages: To upgrade all installed packages to their latest versions, use the following command:
  • pkg upgrade

    Setting Up Development Environments in Termux

    One of the most powerful features of Termux is its ability to set up development environments right on your Android device. Here are a few examples:

    Setting Up Python

    To set up a Python development environment in Termux:
    1. Install Python:
      pkg install python
    2. Check if Python is installed:
      python --version
    3. You can now use Python in Termux to run scripts, install packages using pip, and even use the built-in REPL (Read-Eval-Print Loop).

    Setting Up Node.js

    To set up Node.js:
    1. Install Node.js:
      pkg install nodejs
    2. Check the installed version:
      node --version
    3. You can now use npm (Node Package Manager) to install JavaScript packages.

    Setting Up Git

    If you’re working on a project with version control, Git is a useful tool:
    1. Install Git:
      pkg install git
    2. Check if Git is installed:
      git --version
    3. You can now clone repositories, commit changes, and push to remote repositories from within Termux.

    Using Termux for Networking Tasks

    Termux also provides a range of networking tools that you can use for tasks like downloading files, checking network connections, or even creating servers. Some useful networking commands include:
    • curl: A command-line tool to transfer data from or to a server.
      curl -O https://example.com/file.zip
    • ping: A command used to check the network connection to a specific host.
      ping google.com
    • ssh: Termux can be used as an SSH client to connect to remote servers.
      pkg install openssh
      ssh user@host
    • wget: Another command to download files from the internet.
      pkg install wget
      wget https://example.com/file.zip

    File Management in Termux

    You can use Termux to manage files on your device, including accessing storage locations outside of Termux’s sandboxed environment.

    Accessing Shared Storage

    By default, Termux has limited access to your device’s storage. To gain access to your shared storage (e.g., the internal storage), you need to run the following command:
    termux-setup-storage
    This command will grant Termux permission to access the shared storage and create a new directory named storage in your home directory. Inside storage, you’ll find shortcuts to different storage locations such as:
    • storage/shared: External storage (e.g., SD card or shared storage).
    • storage/downloads: Downloads folder.
    • storage/emulated/0: Internal storage.

    Accessing Files

    Once you’ve set up storage access, you can easily navigate through and manipulate your files.
    cd /data/data/com.termux/files/home/storage/shared

    Termux and Scripting

    Termux is an ideal environment for writing and running shell scripts, which are a series of commands that can be executed automatically. Here’s how to write and run a basic shell script in Termux:

    Create a New Script

    You can use a text editor like nano or vim to create a script. For example, let’s create a simple “Hello, World!” script.
    1. Open the editor:
      nano hello.sh
    2. Write the following code in the editor:
    #!/bin/bash
    echo "Hello, World!"
    1. Save and exit the editor by pressing CTRL + X, then Y to confirm, and Enter.

    Make the Script Executable

    Before you can run the script, you need to make it executable:
    chmod +x hello.sh

    Run the Script

    Now, you can run the script:
    ./hello.sh

    Termux Extras

    Termux provides several additional features that can enhance your experience:
    • Using the Termux Widget: Termux supports widgets that you can place on your home screen for quick access to commands or scripts.
    • Customizing the Prompt: You can change the appearance of your Termux prompt by modifying the ~/.bashrc or ~/.zshrc files to suit your preferences.
    • Running Servers: You can use Termux to run servers directly from your device. For example, you can set up a web server using Python or Node.js.

    Conclusion

    Termux is an incredibly versatile tool that allows you to turn your Android device into a powerful Linux workstation. From basic file management and system administration to setting up development environments and networking tasks, Termux provides a wide range of features that can help you become more productive on the go. By following