Programming on the phone using Termux terminal emulator

    Greetings to readers! In this article I will talk about how you can write programs using an android phone. I say right away - root rights are not needed.

    What do we need?


    The first thing we need is an android phone with the Termux application installed on it (available on Google Play ). To fully work with the terminal, we need enough memory. With dozens of installed packages, the application takes up 1.5 GB of memory.
    Also, for comfortable coding, it is desirable that the phone is with OTG support, and you had a keyboard with a USB connection to write code on the keyboard (much more convenient). If this is not the case, then download the Hacker's Keyboard . It has a Ctrl key, which is important to us.



    Why Termux?


    Termux has in its arsenal enough packages for working with programming languages: C / C ++, Python, Golang, PHP, Lua.
    There are also databases, I only know about mariadb and postgresql.

    Start


    image
    Each time the application starts, we see a greeting that indicates the basic commands for working with the terminal:
    • pkg search - a command to search for packages. Example: pkg search vim
    • pkg install - command to install the package. Example: pkg install vim


    For coding, we need a text editor. There are different options, I chose Vim and briefly tell you how to work with it.
    Install vim:
    $ pkg install vim

    For an example of working with vim, we will write “Hello World” in C.
    $ vim main.c

    After that, Vim will start. To start writing code, you need to press the "i" key.
    We write the code:
    #include 
    int main()
    {
           printf("Hello World!\n");
           return 0;
    }
    

    After that, press the Esc key, put a colon and write wq (": wq"). This will save our file and changes in it (w - write) and close it (q - quit).

    It's important to know!

    w - save changes to file
    wa - save changes to all files
    q - close file
    qa - close all files
    wq - save changes and close file

    Now we need to compile this code. First, install the compiler:
    $ pkg install gcc

    Next, write the following:
    $ gcc -Wall main.c -o program

    main.c - file with our code
    program - our program.

    Now we can run our program and see if it works:
    $ ./program

    or
    $ sh program

    Result:
    Hello World!


    the end


    This was an introduction to programming on the phone. Please write in the comments if a continuation is needed: working with databases, code examples and running them on other PLs, working with the terminal itself, and so on.

    Also popular now: