Sometimes you need to work on the go. Termux provides a terminal environment on your Android phone. This is written for me, but others made find it useful.
Install termux
Termux is no longer releasing current versions on Google Play. Hence, first install F-Droid. Then search for “termux” and install it!
Then update and upgrade to ensure you have the latest packages.
pkg update
pkg upgrade
Some of the later packages (R) require x11 libraries. Hence, simply install the termux recommended packages
pkg install x11-repo
pkg install root-repo
apt autoremove
If you want termux, you likely want to grant it access to local storage:
termux-setup-storage
The above must be done in the termux window, so the pop-up can be enabled.
ssh access
You likely want ssh access:
pkg install openssh
sshd
You likely want to bring over your ssh keys from your other machine:
scp user@host.com:.ssh/authorized_keys .ssh/.
sshd
Other termux useful packages
Then install your most useful packages!
Python
I use a significant number of python packages. Here are some that are typically desired:
Jupyterlab
I want python including jupyterlab as well as other scientific python packages. A good repository for that is https://its-pointless.github.io
This sequence was required to satisfy some dependencies which otherwise wouldn’t compile.
pkg install git python emacs rsync rust binutils cmake build-essential make clang flang
curl -LO https://its-pointless.github.io/setup-pointless-repo.sh
bash setup-pointless-repo.sh
pip install ruamel.yaml==0.17.21
pkg install libandroid-spawn patchelf ninja
pip install jupyter
pip install pgen
Scipy, Pandas
An additional repository is necessary (for simplicity)
pkg install tur-repo
pkg install python-numpy python-pandas python-scipy
Plotly, plotly
pkg install libjpeg-turbo
pip install sympy
pip install plotly
Apache
Just in case you want to web serve:
pkg install apache2
R
As of the date of publication, the termux repo maintained version of r (https://www.r-project.org/) does not work due to library linking and consistencies. however, compilation is relatively straightforward assuming the following is completed.
pkg install make clang openssl libcurl libicu libxml2 wget which
VERSION=4.3.2
wget https://cran.r-project.org/src/base/R-4/R-${VERSION}.tar.gz
tar xavf R-${VERSION}.tar.gz
cd R-${VERSION}/
mkdir -p $PREFIX/local/R-${VERSION}
CFLAGS='-O2' CXXFLAGS='-O2' FFLAGS='-O2' LTCFLAGS='-g -O2' CC=clang CXX=clang++ OBJC=clang FC=flang-new ./configure --enable-R-shlib --prefix=$PREFIX/local/R-${VERSION} --with-x=no
make -j4
make install
echo export PATH=/data/data/com.termux/files/usr/local/R-${VERSION}/lib/R/bin:\$\{PATH\} >> ~/.bashrc && source ~/.bashrc
Subsequently, install any necessary packages
Install some dependencies:
pip install ambiance
pkg install libcairo xorgproto gdal
pkg install bthread-dev libcairo
pkg install pandoc
Prepare for compiling within R. (For some reason, on one of my installations of termux, the local dictory was not in the include path, hence it is added with this file.)
mkdir R-packages
cd R-packages
mkdir ~/.R
cat << EOF >> .R/Makevars
PKG_LIBS+=-lbthread
CXXFLAGS+=-I.
CFLAGS+=-I.
EOF
There are a few R packages which are problematic and it is wise to install these first. First, get the patches. Originally they are distributed from its-pointless however, I had to update the patches are they are best downloaded from my own fork (as of publication of this post).
wget https://raw.githubusercontent.com/gustafson/gcc_termux/master/R-patches/later-tincythread.h.patch
wget https://raw.githubusercontent.com/gustafson/gcc_termux/master/R-patches/rcran-fs-Makevars.patch
wget https://raw.githubusercontent.com/gustafson/gcc_termux/master/R-patches/rcran-fs-id.cc.patch
wget https://cran.r-project.org/src/contrib/fs_1.6.3.tar.gz
tar xavf fs_1.6.3.tar.gz
patch -p0 < rcran-fs-id.cc.patch
patch -p0 < rcran-fs-Makevars.patch
wget https://repo.miserver.it.umich.edu/cran/src/contrib/later_1.3.1.tar.gz
tar xavf later_1.3.1.tar.gz
patch -p0 < later-tincythread.h.patch
The launch R and install it those:
install.packages("/data/data/com.termux/files/home/R-packages/fs", repos = NULL, type = "source")
install.packages("/data/data/com.termux/files/home/R-packages/later", repos = NULL, type = "source")
And then follow up with the remaining packages. For example:
install.packages("knitr")
install.packages("rmarkdown")
install.packages("bookdown")
install.packages("svglite")
install.packages("DT")
install.packages("reticulate")
install.packages("leaflet")
Termux other stuff
mkdir -p .termux/boot
echo "termux-wake-lock && sshd" >> ~/.termux/boot/start-sshd
apt install termux-api termux-services