Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Linux Terminal on Android: How to Use It

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes, you can run a real Linux terminal on Android without rooting your phone. The easiest way is to install a terminal emulator app and, if you need actual Linux commands and packages, a userland environment like Termux. This guide walks you through setting up Termux, which gives you a full Linux command-line experience (bash, package manager, file access) on your Android device. You'll need an Android phone or tablet with internet access and about 200 MB of free storage.

What You'll Need

  • An Android device (phone or tablet) running Android 7 or newer.
  • Internet connection to download the app and packages.
  • Optional: a physical keyboard (Bluetooth or USB) for easier typing, but not required.

Step-by-Step

  1. Install Termux from the official source. Open the Google Play Store on your Android device, search for “Termux”, and install it. Alternatively, you can download the APK from the official Termux GitHub releases page, but the Play Store version is simplest and safest. (Note: The Play Store version may be older than the GitHub one; both work fine for basic use.)
  2. Open Termux. Tap the Termux icon to launch it. You'll see a black screen with a command prompt that looks like $ or ~$. This is your Linux shell.
  3. Update the package list. Type pkg update and press Enter. This fetches the latest list of available software from Termux's repositories. Wait for it to finish; it may ask for confirmation to download packages – type y and press Enter if prompted.
  4. Upgrade installed packages. Type pkg upgrade and press Enter. This updates any existing packages to their latest versions. Again, confirm with y if asked. This step ensures you have the latest security patches and bug fixes.
  5. Install essential packages. Type pkg install nano git curl and press Enter. This installs the nano text editor, git for version control, and curl for downloading files. You can install more later as needed. Confirm any prompts with y.
  6. Test a basic command. Type echo "Hello from Linux" and press Enter. You should see the output Hello from Linux. This confirms your terminal is working.
  7. Navigate your file system. Use ls to list files in the current directory, cd to change directories (e.g., cd /sdcard to access your phone's internal storage), and pwd to see where you are. Note: Termux starts in its own home directory (like /data/data/com.termux/files/home), but you can access Android storage via /sdcard or /storage/emulated/0.
  8. Install a more advanced shell (optional). If you prefer zsh, type pkg install zsh and then chsh -s zsh to make it your default shell. But bash (the default) is fine for most.
  9. Run a GUI app (optional). Termux can run graphical apps if you install a VNC server and a desktop environment like XFCE. This is more advanced; for now, focus on command-line tools.

Common Mistakes

  • Using apt instead of pkg. Termux uses its own package manager wrapper pkg which handles dependencies and mirrors correctly. Using apt directly may work but can cause issues; stick to pkg.
  • Installing from unknown APK sources. Only install Termux from the Play Store or the official GitHub. Unofficial versions may be malicious.
  • Not updating packages. Skipping pkg update and pkg upgrade can lead to broken installations because packages depend on updated libraries.
  • Assuming you have root access. Termux does not require root, and most commands work without it. But you cannot modify system files or use sudo unless you have rooted your device (which is not recommended).

Tips

  • Use the volume-down button as a Ctrl key. In Termux, pressing and holding the volume-down button on your phone turns it into a Ctrl key, allowing shortcuts like Ctrl+C (copy) and Ctrl+Z (suspend). This is essential for command-line work.
  • Enable the extra keys row. Swipe from the left edge of the screen to open the navigation drawer, go to “Extra keys”, and toggle it on. This adds a row of useful keys (ESC, TAB, CTRL, ALT, etc.) above the keyboard.
  • Access Android storage easily. Use cd /sdcard to go to your internal storage. For external SD cards, the path may vary; check with ls /storage/.
  • Back up your Termux home. You can copy your home directory to your Android storage with cp -r ~ /sdcard/termux-backup to save your files.

Troubleshooting

If Termux crashes on startup: Clear the app's data (Settings > Apps > Termux > Storage > Clear Data). This will delete your files inside Termux, so back them up first if possible. Then reopen Termux and run pkg update again.

If pkg update fails with a network error: Check your internet connection. Sometimes Termux's default mirror is down; you can switch mirrors by editing the file $PREFIX/etc/apt/sources.list and changing the URL to a different mirror from the official list. But this is advanced; first try restarting your router or using mobile data.

If commands are not found after installation: Run pkg update again and then pkg install again. Sometimes the package list is stale.

If you get a “Permission denied” error: You are trying to access a file or directory that Android restricts. Use termux-setup-storage to grant Termux access to your storage. This command creates a storage folder in your home directory with symlinks to your Android storage.

Frequently Asked Questions

Is Termux safe to install?

Yes, when installed from the Google Play Store or the official GitHub repository, it is safe. It does not require root and runs in a sandboxed environment.

Can I run sudo commands?

No, unless your device is rooted. Termux does not include sudo by default, and using root is not recommended for security. Most tasks can be done without root.

How do I install Python or Node.js?

Simply type pkg install python or pkg install nodejs. These are available in the Termux repositories.

Can I access my phone's files from Termux?

Yes, after running termux-setup-storage, you can access your internal storage via ~/storage/shared or directly via /sdcard.

Why is the terminal different from Ubuntu?

Termux uses its own environment (based on Android's Linux kernel) and its own package repositories. It is not a full Linux distribution like Ubuntu, but it provides the same command-line tools and shell experience.

Can I run GUI applications?

Yes, with extra setup. You can install a VNC server and a lightweight desktop environment like XFCE, then connect via a VNC viewer app. This is more complex and requires a bit of Linux knowledge.