Install SearXNG in Termux
This guide explains how to reinstall SearXNG from scratch on Termux. It includes all required steps, common errors, and fixes, so it can be used as a reference for future installations.
SearXNG Installation Guide for Termux (From Scratch)
This guide covers the full process of installing SearXNG on Termux, including required dependencies and workarounds for issues encountered during installation.
Prerequisites
- A working Termux installation on your Android device
- An active internet connection
Step 1: Cleanup Previous Installation (For Reinstallation Only)
If you are reinstalling SearXNG, start with a clean setup. Skip this step if this is your first installation.
# Deactivate virtual environment if active
deactivate 2>/dev/null || true
# Remove old SearXNG source code and virtual environment
rm -rf ~/searxng-src
rm -rf ~/searxng-pyenv
# Remove old configuration directory
rm -rf ~/.config/searxng
echo "Previous SearXNG files removed (if they existed)."
Step 2: Update and Upgrade Termux Packages
Always start with an up-to-date Termux environment.
pkg update && pkg upgrade -y
Step 3: Install Essential System Packages
Some Python packages require native compilation. The following packages are required.
pkg install -y git python libxml2 libxslt clang binutils
Step 4: Clone the SearXNG Repository
Clone the SearXNG source code into your home directory.
cd ~
git clone https://github.com/searxng/searxng searxng-src
Step 5: Create and Activate a Python Virtual Environment
Using a virtual environment keeps dependencies isolated.
python -m venv searxng-pyenv
source searxng-pyenv/bin/activate
Step 6: Install Python Build Tools and Core Dependencies
This prevents common installation errors related to missing Python modules.
pip install --upgrade pip setuptools wheel pyyaml pybind11
Step 7: Install SearXNG and Dependencies
Install SearXNG in editable mode as recommended.
cd ~/searxng-src
pip install --use-pep517 --no-build-isolation -e .
Step 8: Configure SearXNG
Create the configuration directory, copy the default settings file, and generate a secret key.
# Create configuration directory
mkdir -p ~/.config/searxng
# Copy default settings file
cp searx/settings.yml ~/.config/searxng/settings.yml
# Generate and set secret_key
python -c 'import os, yaml; p=os.path.expanduser("~/.config/searxng/settings.yml"); d=yaml.safe_load(open(p)); d["server"]["secret_key"]=os.urandom(24).hex(); yaml.dump(d, open(p,"w"))'
How to Run SearXNG
Activate the virtual environment and start the server.
source ~/searxng-pyenv/bin/activate
cd ~/searxng-src
export SEARXNG_SETTINGS_PATH=~/.config/searxng/settings.yml
python searx/webapp.py
SearXNG will be available at http://127.0.0.1:8888.
Running SearXNG in the Background (tmux)
Use tmux to keep SearXNG running in the background.
pkg install -y tmux
tmux
Inside tmux, run:
source ~/searxng-pyenv/bin/activate
cd ~/searxng-src
export SEARXNG_SETTINGS_PATH=~/.config/searxng/settings.yml
python searx/webapp.py
Detach from tmux:
Ctrl + B
D
To reattach:
tmux attach
To stop SearXNG, reattach and press Ctrl + C, then exit tmux.
Credit: u/jamaalwakamaal