Turns out, GCC in Termux is faster than half the setups I’ve seen.
I was stuck in traffic with nothing but my phone when an idea for a C program hit me—something small, but useful. No laptop, no IDE, no fancy setup. Just me, my thoughts, and a stubborn itch to code.
Then I remembered Termux. Within minutes, I had GCC in Termux installed, and I was writing C on my phone like it was no big deal. It wasn’t just a workaround—it was liberating.
If you’re the kind of dev who hates waiting for “the perfect setup,” this guide is your shortcut. Let’s get you coding in C anytime, anywhere—with nothing but your Android phone.
Download my FREE Termux Cheat Sheet Now!
Clarifying GCC and Clang in Termux
While the article suggests installing GCC, it’s important to note that Termux primarily uses Clang as its compiler. The gcc
command in Termux is typically a symlink to Clang, maintained for compatibility with build scripts expecting GCC. Clang is a modern compiler that is actively maintained and often preferred for its performance and diagnostics. Understanding this can help you better interpret compiler messages and behavior in Termux.
· · ─ ·𖥸· ─ · ·
Understanding Termux’s Package Management
Termux uses its own package management system, pkg
, which is a wrapper around apt
. This system allows you to install, update, and manage packages within the Termux environment. For example, to install Clang, you would use:
pkg install clang
This command fetches and installs the Clang compiler, enabling you to compile C programs directly in Termux. Familiarity with pkg
is essential for managing your development tools in Termux.
· · ─ ·𖥸· ─ · ·
Setting Up a Development Environment
Beyond installing the compiler, setting up a comfortable development environment is crucial. Termux doesn’t come with a text editor by default, so you’ll need to install one. For instance, to install nano
, a user-friendly text editor, use:
pkg install nano
Once installed, you can create and edit your C source files directly in Termux. Additionally, understanding file permissions is important. After compiling your program, ensure it’s executable by setting the appropriate permissions:
chmod +x your_program
This command makes your compiled program executable, allowing you to run it with ./your_program
.
· · ─ ·𖥸· ─ · ·
Installing GCC in Termux
Before you can start writing and compiling C programs on your Android device, you’ll need to set up your development environment in Termux. The good news? It’s simpler than it sounds. In Termux, the gcc
command is actually a symlink to Clang, a modern compiler that works seamlessly with most C codebases. Using Termux’s package manager (pkg
), you can quickly install Clang and supporting tools with just a few commands—no root, no bloated IDEs, and no nonsense. Let’s walk through the essentials to get you compiling like it’s second nature.
Prerequisites
Before you begin, ensure that you have Termux installed on your Android device. You can download it from the Google Play Store or F-Droid.
Update Termux Packages
To install GCC in Termux for C++ programming, you need to install the clang
package, which includes the GCC compiler. Run the following command in Termux:
pkg update
pkg upgrade
Install GCC
To install GCC for C++ programming in Termux, you need to install the clang
package, which includes the GCC compiler. Run the following command in Termux:
pkg install gcc
This command will install GCC in Termux, enabling you to compile C++ code.
Verify GCC Installation
After installation, verify that GCC is installed correctly by checking the version:
g++ --version
You should see output indicating the version of the compiler, confirming that you have successfully installed GCC in Termux for C++ programming.
Write and Compile a C++ Program
Once you install GCC in Termux for C++ development, it’s time to test the setup by writing and compiling a simple C++ program. Use a text editor like nano
to create your first C++ file:
nano hello.cpp
Add the following C++ code to hello.cpp
:
#include <iostream>
int main() {
std::cout << "Hello, Termux!" << std::endl;
return 0;
}
Save the file and exit the editor. Compile the program using GCC in Termux:
g++ -o hello hello.cpp
Run the compiled program:
./hello
You should see the output: Hello, Termux!
, confirming that your C++ development environment is working.
· · ─ ·𖥸· ─ · ·
Additional Tips
- Libraries and Dependencies: If your C++ program requires additional libraries, you can install them using Termux’s package manager (
pkg
). - IDE Support: Consider using a text editor like
vim
oremacs
in Termux for more advanced coding features. - GDB: Install
gdb
for debugging your C++ programs:
pkg install gdb
· · ─ ·𖥸· ─ · ·
Why This Changes Everything
GCC in Termux strips away the excuses. No more saying, “I’ll code that later.” You now have a full C dev environment in your pocket—free, open source, and ridiculously portable.
Whether you’re a student, tinkerer, or FOSS-loving nomad, this setup gives you the power to build and test C code wherever you are. No subscriptions. No bloated apps. Just you and your craft.
If this kind of lightweight, on-the-go development excites you, I’ve got more where this came from. Subscribe to the newsletter and stay in the loop with tutorials, tools, and unapologetically FOSS workflows.
Leave a Reply