Code With Your Phone

Introduction

Software continues to eat the world, and everyone needs to learn to code. In 1995, Steve Jobs, in an interview with Robert Cringley stated, “Everybody should learn to program a computer because it teaches you how to think.” Learning to program a computer is not necessarily to create the next most in-demand software product, although you can make it your goal. It is rather, to help you learn how to give clear instructions for the computer.

You Can Use Your Phone

In the modern world, almost everybody has a smartphone or a tablet that runs either the Android or the iOS operating system. With any of these devices, you can quickly set it up to start coding right away by following this post.

Requisites

The application that gives you similar capabilities as your computer is the Termux Terminal Emulator. To install Termux, we will first install the F-Droid application, which is similar to Google’s Play Store. Then, we will proceed to install any programming language of our choice.

Installing F-Droid

F-Droid is a client application that acts as a portal for browsing Free and Open Source Software (FOSS) available in its repository. This application has been described as an alternative to the Google Play Store. To install F-Droid, follow these steps:

  1. Visit the F-Droid download page.

  2. Tap on the Download F-Droid button as shown below

  3. Enable installing from unknown sources when prompted.

  4. After the download is complete, search for the APK file in your downloads and tap on it.

  5. Wait for the installation to complete. After the installation, wait a few moments for F-Droid to download the necessary information from the default software repository.

  6. Find the F-Droid application on your phone’s desktop. Tap on it to start.

  7. When it starts, wait for it to update the repositories. You will then see a list of the latest free and open-source applications.

Installing Termux

Termux is an open-source software project by a group of dedicated developers who thought of making it possible to give the mobile phone similar capability as the laptop or desktop computer for coding. With Termux, you can learn and code in most programming languages such as C/C++, Objective-C/C++, Java, Python, HTML/CSS, JavaScript etc. right on your phone.

With the F-Droid application still open, follow these steps to install Termux.

  1. Tap on the green search button at the bottom right corner of the screen.

  2. Type termux in the search bar and tap on the search arrow button.

  3. Tap on Termux Terminal Emulator with packages from the list of applications.

  4. Tap on the install button and wait for the installation to complete.

Setting Up Termux

At this stage, we have successfully installed Termux. We will now proceed to set it up. We will first update the Termux machine, and install Python3, Clang, a code editor and any additional language of our choice. Tap on the Termux application icon to start it.

  • Type the following command to update the Termux machine

    pkg update && pkg upgrade

The screen will be flooded with several texts as Termux checks for updates. When prompted with the question, “Do you want to continue? Y/n,” type y and press the enter key. Wait for the update to complete.

  • Grant Termux access to the phone’s storage. This will enable Termux to save any file you create. Type this command and press the enter key.

    termux-setup-storage

  • Next, type the following and press the enter key

    pwd

This command means print the working directory. It instructs Termux to print the path to its home directory. You will see something similar to /data/data/com.termux/files/home

  • Type this and press the enter key.

    ls

This command instructs Termux to display all the files and directories (folders) inside the current directory. The directories are colored blue or similar depending on your system. You will see storage as one of them. This is the main storage directory for the phone.

  • Type the following command and press the enter key.

    cd storage

The cd stands for change directory. It instructs Termux to move into a specified directory, storage in our case. After pressing the enter key, you will see the path change from ~ $ to ~/storage $. We are now in the storage directory. You can check what files and directories are in the storage folder by using the ls command as we did earlier.

Note

You can get rid of the text on the screen by typing clear and pressing the enter key. This command instructs Termux to clear the screen. It does not affect any file or directory on your device.

  • We can now install the packages we will need to start coding. Let's start with the following.

    pkg install git curl wget

These packages will help you to clone and download files from the internet which can enhance your programming experience.

  • The next package to install is the following.

    pkg install vim

The Vim package is an editor with multiple capabilities. It can be used to code and type any document. When prompted to continue, type y and press the enter key. Check out this tutorial for how to use the Vim editor.

  • The next package to install is Python.

    pkg install python3

Python is a high-level programming language used to develop a plethora of programs including web applications, desktop applications, and games, used in machine learning and artificial intelligence among others. It is used by top companies around the world. It is one of the most in-demand programming languages of the 21st century and it is surprisingly easy to learn.

  • The next package to install is apache2

    pkg install apache2

Apache2 is a free and open-source application that enables you to host your website locally on your device for testing.

  • Finally, those who would like to program in C/C++, Objective-C/Objective-C++, Java, Fortran, Ada, Go, D, and Modula-2 can proceed to install the Clang package.

    pkg install clang

The Clang package comes with a compiler to help you debug your code.

Conclusion

That is all for now. We have successfully installed and set up Termux for programming. You can now use your phone to code as you will on a laptop or desktop computer at any time, anywhere. You can also install additional packages as you may need. Check out the next post, which takes you through using Vim.

Have any questions or suggestions, let me know your thoughts in the comment box.

2
Subscribe to my newsletter

Read articles from Emmanuel Enchill directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Emmanuel Enchill
Emmanuel Enchill

I am a passionate software engineer in training at ALX. I have a strong preference for back-end development. I am on course to share my learning journey with you.