Okay, here is a comprehensive guide to reinstall SearXNG from scratch on Termux, summarizing all the steps we went through, the errors you encountered, and their solutions. This should serve as a reliable reference for future installations.
SearXNG Installation Guide for Termux (From Scratch)
This guide covers the full process of installing SearXNG on Termux, including all necessary dependencies and workarounds for issues encountered.
Prerequisites:
* A working Termux installation on your Android device.
* An active internet connection.
Step 1: Cleanup Previous Installation (For Reinstallation Only)
If you're reinstalling, it's best to start clean. Skip this step if this is your very first attempt.
# 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
We encountered issues where python-dev was not available, and uvloop required binutils for compilation. clang is also crucial for compiling Python packages with C extensions.
pkg install -y git python libxml2 libxslt clang binutils
Step 4: Clone 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 is best practice to keep SearXNG's dependencies isolated from your main Termux Python installation.
python -m venv searxng-pyenv
source searxng-pyenv/bin/activate
(Your prompt will change to (searxng-pyenv) ~$ indicating the virtual environment is active.)
Step 6: Install Python Build Tools and Core Dependencies
We previously faced BackendUnavailable: Cannot import 'setuptools.build_meta' and ModuleNotFoundError: No module named 'yaml' errors. This step ensures pip, setuptools, wheel, and pyyaml are correctly installed and up-to-date within your virtual environment. We also add pybind11 here, which was required by fasttext-predict.
pip install --upgrade pip setuptools wheel pyyaml pybind11
Step 7: Install SearXNG and its Dependencies
Navigate into the cloned source directory and install SearXNG in "editable" mode (-e .), which is what the official guide recommends. This step will also handle other dependencies like uvloop, which now has binutils available.
cd ~/searxng-src
pip install --use-pep517 --no-build-isolation -e .
Step 8: Configure SearXNG
First, create the configuration directory, then copy the default settings.yml (we found it's located under the searx subdirectory). Finally, generate and set your unique secret_key.
# Create the configuration directory
mkdir -p ~/.config/searxng
# Copy the default settings file (corrected path)
cp searx/settings.yml ~/.config/searxng/settings.yml
# Generate and set the secret_key automatically
python -c 'import os; import yaml; settings_path = os.path.expanduser("~/.config/searxng/settings.yml"); with open(settings_path, "r") as f: settings = yaml.safe_load(f); settings["server"]["secret_key"] = os.urandom(24).hex(); with open(settings_path, "w") as f: yaml.dump(settings, f, default_flow_style=False)'
# (Optional) You can manually verify the secret_key or make other customizations:
# nano ~/.config/searxng/settings.yml
How to Run Your SearXNG Instance
Once installed, use these commands to start your SearXNG server.
* Activate your virtual environment:
source ~/searxng-pyenv/bin/activate
* Navigate to the SearXNG source directory:
cd ~/searxng-src
* Start the SearXNG web application:
(Note the corrected path for webapp.py)
export SEARXNG_SETTINGS_PATH=~/.config/searxng/settings.yml
python searx/webapp.py
You should see output indicating that SearXNG is starting and listening on http://127.0.0.1:8888.
* Access in Browser: Open your Android device's web browser and go to http://127.0.0.1:8888.
* To Stop SearXNG: Go back to your Termux terminal and press Ctrl + C.
Running SearXNG in the Background (using tmux)
To keep SearXNG running even if you close Termux or switch to other apps, use tmux.
* Install tmux (if you haven't already):
pkg install -y tmux
* Start a new tmux session:
tmux
(Your screen will clear, and you'll be in a new tmux session.)
* Inside the tmux session, run your SearXNG commands:
source ~/searxng-pyenv/bin/activate
cd ~/searxng-src
export SEARXNG_SETTINGS_PATH=~/.config/searxng/settings.yml
python searx/webapp.py
SearXNG will start running.
* Detach from the tmux session:
* Press Ctrl + B (release both)
* Then press D
(You will be returned to your regular Termux prompt, and SearXNG will continue running in the background.)
* To Reattach to your tmux session (to see SearXNG's output or stop it):
Open Termux again and type:
tmux attach
(This will bring you back to the session where SearXNG is running.)
* To Stop SearXNG from a tmux session:
* Reattach to the tmux session (tmux attach).
* Press Ctrl + C in the tmux window where SearXNG is running.
* You can then close the tmux session by typing exit or Ctrl + D.
This comprehensive guide should help you manage your SearXNG installation on Termux effectively!
Credit: u/jamaalwakamaal/