How to compile Python and C++ code on your Android tablet with Termux

  • Termux offers a complete Linux environment on Android to run and compile Python, C, and C++ code without requiring root access.
  • The combination of Python, Clang, and tools like Nano, OpenSSH, and Screen allows you to develop and manage real projects from a tablet.
  • Termux makes it easy to learn programming, automation, and cybersecurity through practical projects and reusable scripts.
  • What you learn in Termux can then be scaled to servers, cloud environments, and professional development and security solutions.

Basic Termux commands and tricks to master Linux on Android

If you've ever thought that for To program in Python or C++, you absolutely needed a laptop.It's time to change your mindset: with an Android tablet and Termux, you can set up a pretty serious development environment. You don't need root access, you don't need expensive equipment, and you can practice at home, on the subway, on the sofa, or wherever you happen to be.

In this guide I'm going to tell you, step by step, how Compile Python and C++ code directly on your tablet with TermuxYou'll learn which packages to install, how to configure the environment, and how to leverage it to learn programming, automation, and even cybersecurity without any hassle. Plus, you'll find practical usage tips, project ideas, and some tricks to turn your phone or tablet into a handy mini Linux lab.

What is Termux and why is it so useful for programming on a tablet?

Termux is an app that combines a terminal emulator and a Linux environment Adapted for Android. Basically, it opens a bash console within your device, with its own package tree and commands, so it behaves almost like a Linux distro… with a couple of important details to keep in mind.

The funny thing is that You don't need root to use TermuxYou install it from Google Play or F-Droid, open it, and you're in a working terminal. From there, you can install Python, Clang, servers, networking tools, window managers, and much more, using typical Linux commands like pkg o apt.

When starting the application, Termux greets you with a bash shellwhere you can run commands, create scripts, compile code, and generally work as if you were on a single-user Linux machine. It's ideal for learning the command line if you're coming from Windows or if you want to practice system administration in a light way.

There are some particularities: Termux functions as a single-user systemSo you don't have separate accounts or the command sudoYou have full permissions within your directory $ HOMEBut outside of that, access is much more limited and you won't be able to, for example, install things outside the prefix that the app uses.

Another important difference is that Termux shares the file system with AndroidHowever, it doesn't follow the classic FHS standard. Instead of using /usr or /home where it always was, everything resides in internal application paths: the package installation prefix is ​​in $PREFIX = /data/data/com.termux/files/usr and your personal directory is $HOME = /data/data/com.termux/files/homeThat's why you'll see some unusual paths compared to a desktop Linux system.

Access to storage and file structure in Termux

Within Termux you can Work seamlessly in $HOME: create scripts, grant execution permissions, and launch programs with ./nombre_scriptThat's where you should store your Python and C/C++ code to avoid permission limitations and other issues.

If you want to access the internal memory or the SD card, you can use the command termux-setup-storageThis command creates a directory $HOME/storage which acts as a link to the device's memory card or shared storage. From there, you can read and write files as if you were in any Android user folder.

There's a catch: You cannot mark a script as executable in paths under storage. and run it directly with ./script.pyIn those locations you must always explicitly invoke the interpreter, for example: python storage/.../script.pyThis is due to how Android manages permissions on shared storage.

If you need a more "normal" Linux-style directory structure, there is the option to install termux-proot with pkg install termux-proot and then launch termux-chroot. Thus, You can simulate that $HOME is in /home And that the file system follows a more standard hierarchy, although in reality they are links and layers on top of the actual system, because the Android root directory is read-only and does not allow symbolic links there.

In modern versions of Android, such as Android 10, sometimes termux-setup-storage It does not create the storage directory correctly. In those cases, you can create a manual symbolic link to /sdcard within your $HOME to continue having easy access to shared memory, even though the same direct execution restrictions still apply.

First steps: installing Python and clang on Termux

Termux Android

Before compiling anything, it is advisable update Termux base packagesAs soon as you open the app, run:

$ pkg upgrade

This command checks the versions of everything you have installed and updates them to the latest available in the Termux repositories, preventing strange errors later when installing libraries or compilers.

To run and develop in PythonThe next step is to install the official package:

$ pkg install python

This installs Python 3 and its interpreter, which you can start with python As with python3. In addition, it includes pip, the Python package manager, which will allow you to add external modules such as requests, Pillow or other specific ones that you need for your projects on the tablet.

There is also the package python-tkinterIt's designed for when you want to work with graphical interfaces using Tkinter. It's only recommended to install it if you plan to later configure a graphical environment with a VNC server and a window manager, because If you first install Python, add modules with pip, and then install python-tkinter, that previous installation will be overwritten. And you'll have to reinstall your packages. They aren't completely lost because they're cached, but it's a hassle.

To compile C and C++ in Termux, the key package is clang:

$ pkg install clang

This package installs the clang-based C/C++ compiler, along with the executables you need: gcc for C and g++ for C++In some modern configurations, clang may be installed along with other packages, but it's best to check and run it explicitly to ensure you have everything up and running.

Basic example: compiling and running C and C++ on your tablet

Once you have clang ready, you can Write your first "Hello world" in C directly from the tabletYou will need a text editor to work with source files; one of the most convenient console editors is nanowhich you can install like this:

$ pkg install nano

When finished, create a test file in your working directory:

$ nano hola.c

Inside nano, write your program in C (the typical hello world or any simple test you want). Save using the nano key combination: Ctrl + O To write the file, press Enter to confirm the name and then Ctrl + X to exit the editor and return to the console.

To compile that C code, from the same directory where it is located hello.c lance:

$ gcc -o hola hola.c

This command takes the source file, compiles it, and generates an executable called HelloIf no compilation errors appear, you can run the newly created program with:

$ ./hola

The output should be the message you programmed in your "Hello World" program. With this, you have verified that The chain “edit → compile → run” works perfectly in Termux and that your tablet can act as a C development environment without any problems.

If what you want is compile C++ codeThe command to use is g++For example, you could reuse the same file (although it's not ideal for production) simply by:

$ g++ -o hola_cpp hola.c

The C++ compiler understands most C code, so it will generate a binary called hello_cppAlthough you'll probably see some warning at the exit. In practice, It's best to clearly separate C and C++ code and use the appropriate compiler for each.But this example serves to show that g++ is also operational in Termux.

Run and develop in Python from Termux

Code.

With Python already installed, you can use your Android tablet as portable environment for scripts, automations, and experimentsAccessing the interactive interpreter is as simple as typing:

$ python

From there, you can test code line by line, practice control structures, and test standard functions or libraries. For slightly more serious projects, the usual approach is create .py files with nano or another editor and run them from the console:

$ nano script.py

After writing your code, save it and launch it with:

$ python script.py

Within the Termux environment you have access to pip to install additional packagesFor example, if you're going to do web scraping or work with APIs, you'll probably want to install requests:

$ pip install requests

In some cases, certain pip modules need to be compiled during installation (for example, libraries that include C extensions). That's where Clang also becomes essential on the Python side.Because without a compiler, the installation of those packages will fail.

If you're just starting out with Python, Termux is ideal for moving beyond theory and into practical application. You can create short scripts that solve real-world problems in your daily work, using your tablet's console as if it were a local, always-available mini Linux server.

Recommended packages for working comfortably in Termux

Besides Python and clang, there are a number of tools that They make all the difference when using Termux on a daily basis.Whether you're learning programming, setting up small services, or doing network testing.

One of the essentials is opensshwhich allows you to turn your tablet or mobile phone into an SSH server that you can connect to from another computer:

$ pkg install openssh

Once installed, you can start the service with sshd y connect from your PC to the device's IP address using your Termux username and password. Remember that Android does not allow the use of the standard port 22, so the server listens on the 8022 portIf you want to access it from outside your local network, you would need to configure port forwarding on your router to 8022.

To find out your username within Termux, you can launch whoamiAnd to set a new password, the command is passwdYou will obtain the IP address with ifconfig (or with ip a (if you install additional network tools). With this information, you can SSH and SFTP from a laptop, edit files comfortably, and leave your tablet dedicated to running the processes.

Another very practical use is screen:

$ pkg install screen

With screen you can keep active processes running in the backgroundManage multiple terminal sessions within the same connection and reconnect to them if the console is interrupted. This is very useful if you're setting up a server or if you want to run long-running tasks without worrying about screen lockups.

You'll also find it useful to install procps, which includes tools such as pkill to end processes that are stuck or that you no longer need:

$ pkg install procps

To monitor resources, there is htop:

$ pkg install htop

htop functions as a text-based task manager where you can view CPU and memory usage and control processes. However, It doesn't work perfectly in some recent versions of AndroidSo don't be alarmed if you see any limitations or strange behavior.

Besides nano as the main editor, you can add other small console tools that make daily life easier:

  • net-tools to have commands like ifconfig by hand:
    $ pkg install net-tools
  • wget To download content from URLs directly to the tablet:
    $ pkg install wget
  • tree To view the directory structure in tree form:
    $ pkg install tree

Setting up a lightweight graphical environment with VNC and window managers

Android Malware FvncBot, SeedSnatcher and ClayRat: how they attack your mobile

Although Termux shines above all as console and server environmentIf you'd like to experiment, you can also set up a graphical environment accessible via VNC. It's not essential for compiling Python or C++, but it's useful if you want to try out Tkinter interfaces or use a graphical file explorer.

The first step is to install X11 support and a VNC server such as TigerVNC:

$ pkg install x11-repo
$ pkg install tigervnc

Doing this creates the directory ~/.vncwhich, among other files, contains xstartupThis is where you configure which desktop or application is launched when the VNC server starts. You will edit this file later depending on the window manager you choose.

To start the server, run:

$ vncserver

The first time, it will ask for a username and password for remote access. If the process completes successfully, you will see a message similar to New 'localhost:1 ()' desktop is localhost:1, indicating the number of virtual desktop that has been created.

Next, you need to export the environment variable DISPLAY so that graphical applications know where to draw their interface:

$ export DISPLAY=":1"

The value in quotes corresponds to the desktop indicated after starting vncserver; if it shows you a different number, you adjust it. You will need to configure this variable in the sessions where you want to launch graphical programs.or automate it with a startup script.

Note that the VNC server will not listen on the standard port 5900, but on the 5901 portDue to typical Android restrictions, you can connect to the tablet's IP address using a VNC client on your PC, specifying the port, and view what's running in the Termux graphical environment.

By default, if you don't modify the xstartup file, when you connect you'll see little more than a terminal consolewhich doesn't offer much more than what you already have with SSH. To get the most out of it, you need to install a window manager.

If you want something light and simple, a very useful option is flux box:

$ pkg install fluxbox

Then you edit ~/.vnc/xstartup with nano so that, instead of launching the basic console, Start Fluxbox when the VNC server starts.After saving changes, restart vncserver and when you reconnect you will see a functional, lightweight and quite fluid Fluxbox desktop even on modest mobile devices.

Another alternative, with a slightly more extensive list of options (and a slightly heavier load), is open boxwhich you can install with:

$ pkg install openbox pypanel xorg-xsetroot

Just like with Fluxbox, you'll need to adjust the xstartup file to start Openbox Start VNC Server and then restart the service. The choice between Fluxbox and Openbox depends on your preference and your device's resources; on tablets with limited RAM, it's usually better to use the minimum settings.

Once you have the window manager up and running, you can take the opportunity to install graphical tools like pcmanfm with apt install pcmanfm and launch it from the graphical console. You can also try Tkinter interfaces, since with pkg install python-tkinter You will have that module available to create windows, buttons, and other controls visible via VNC.

Learn Python with real-world projects using Termux

python

If you've been taking programming courses for a while but feel that You get stuck between theory and practiceTermux gives you the perfect excuse to get started. Having a Linux environment always in your pocket significantly lowers the barrier to entry: you're not dependent on a laptop, a cumbersome IDE, or endless configurations.

A very effective way to learn is to ask yourself small, real-world projects that you can run directly on the tablet.Instead of limiting yourself to context-free print statements and loops, you create utilities that interact with the network, the file system, or external information. This connects Python syntax to real-world use cases.

A simple but powerful example is a script to automate network checksYou can write a program that periodically pings a list of sites, or that checks for open ports on a specific host. To do this, you'll combine modules such as subprocess o socketsIn addition to Termux's own Linux environment, it fully introduces you to basic concepts of network security and reliability.

Another very useful project is a password strength checkerYou create a script that evaluates whether a key is weak or strong based on its length, use of uppercase letters, numbers, and symbols. Later, you can improve it using regular expressions, word lists, and, if you're up for it, integrate it with files generated from the Termux console itself. At the same time, you reinforce good cybersecurity habits.

You can also mess with a log file analyzerTermux, as a Linux environment, generates logs for both itself and the services you set up. Reading, filtering, and summarizing these logs with Python teaches you how to handle large files, work with lines, patterns, and statistical summaries. It's the gateway to early incident detection tasks, already common practice in security teams.

If you're interested in the web world, a A simple scraper with requests and an HTML parsing library This is another powerful idea. Your script queries a webpage, extracts specific data (prices, headlines, etc.), saves it to files, and can display it on screen or send it to another tool. All of this is done directly from the Termux terminal, which is fantastic for automating small investigations or monitoring risks associated with social engineering.

Finally, something very eye-catching is creating a real-time tracker of weather data or cryptocurrenciesUsing public APIs and HTTP libraries, you can consume data, process it, and display it in the console, updating it at regular intervals. Understanding how to communicate with APIs prepares you to automate tests, create internal services, or even set up secure tunnels and endpoints in more advanced work scenarios.

Focus on cybersecurity and automation from mobile

One of the great advantages of mixing Python, Termux and practical projects The thing is, almost without realizing it, you enter the realm of everyday cybersecurity. Every script you touch can include a layer of awareness, best practices, and ethical reflection on the use of the tools.

For example, when working on password tools, you can linking technical exercises with business security policiesMinimum length, use of password managers, two-factor authentication, etc. If you're in a company, these same scripts can be used to explain to others why certain policies are not whims, but concrete measures against real threats.

When you tinker with system logs and events, you can start to Relate what you see to reference frameworks such as NIST CSF or the NIS2 directiveEven at a basic level, knowing how to interpret patterns, activity spikes, or recurring errors is an essential step in going from a passive user to someone who understands how their infrastructure behaves, however small it may be.

If you take the leap to process automation, Termux and Python help you build repeatable flows that can then be scaled to larger environmentssuch as cloud servers or enterprise infrastructure. What starts as a local script on a tablet can, over time, become part of a larger solution supported by cloud services like AWS or Azure.

This approach also fits very well with teams that develop custom applications, artificial intelligence solutions, or dashboards with BI toolsFirst, you prototype the logic in a Termux script, validate the idea, and then integrate it into a larger architecture that includes AI agents, data pipelines, or business process automation.

On a personal level, using Termux as a testing environment with Python helps you to internalize safety from day oneInput validation, credential management using environment variables instead of hardcoding passwords, caution when using network libraries, etc. These are habits that become natural if you adopt them from the start of programming.

Tips for getting ahead and making the most of Termux

Best cheap mobile phones with a good camera

If you're starting out with a modest mobile phone or tablet and a newly installed Termux, the most sensible thing to do is Start with very small scripts and gradually make the project more complex.Don't try to create a megasystem all at once; add functions and modules as you need them.

It's a good idea to get used to it from an early age. Write logs and handle exceptions in your programsEven if you're in a "toy" environment like your mobile phone, this gives you resilience: when something goes wrong, you'll have clear clues about what happened and you can correct it without going crazy.

As your projects grow, organize your work in separate folders for data, modules, and testsEven though everything is within $HOME in Termux, having a clean structure makes it much easier to find things and reuse code in other ideas that may arise.

Another good habit is document key commands and dependencies that you use. A simple plain text README where you indicate which Termux packages you need (python, clang, openssh, etc.) and which pip modules are required, saves time when you reinstall the app or want to copy the project to another device.

In terms of security, it is important to integrate good practices from day oneAvoid including credentials in your code, use environment variables, validate command-line parameters, and be careful with any network operations performed from scripts. Termux is very powerful, but that's precisely why it should be used wisely.

If you find typing on the touchscreen too limited, you can use... SSH and SFTP for working from a laptopThis leaves the tablet as the server and the large screen for editing and debugging at your leisure. This also makes Termux useful even when you no longer use your mobile phone as your primary device, turning it into a kind of low-power, home mini-server.

Over time, that experience composing and chaining scripts in Termux can be transferred to larger automations in cloud infrastructures or business intelligence toolswhere Python remains the star. In some cases, what you've tested on a small scale on the tablet ends up becoming part of a workflow that integrates with dashboards in Power BI or with AI solutions deployed in professional environments.

Getting used to this cycle of experimenting in Termux, refining your scripts, and then moving them to a more powerful environment is a very practical way to turn your learning into concrete resultsWhether programming is a hobby or you're focused on cybersecurity, custom software development, or business process automation.

In the end, Termux turns your Android phone or tablet into a A portable lab where you can compile C and C++, run Python, set up lightweight services, and practice with networking tools. without relying on large infrastructures. If you take your projects seriously, save your progress, and keep iterating, you'll be surprised how far you can go with just a terminal screen in your pocket.


Add as preferred source in Google