2025-10-23 10:10:29 - 7 Comments
First we ensure that our system is up to date.
sudo apt update
sudo apt upgrade
Next we will install a couple of required packages to create the python environment, read html, xml and communicate with the internet.
sudo -H apt-get install -y python3-dev python3-babel python3-venv python-is-python3 uwsgi uwsgi-plugin-python3 git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev
We need a new user and home directory where we can put the code and script files.
sudo -H useradd --shell /bin/bash --system --home-dir "/usr/local/searxng" --comment 'Privacy-respecting metasearch engine' searxng
sudo -H mkdir -p "/usr/local/searxng"
sudo -H chown -R "searxng:searxng" "/usr/local/searxng"
We also need a configuration file that we will put under etc.
sudo -H mkdir -p "/etc/searxng"
sudo vi /etc/searxng/settings.yml
Configuration below is pretty standard with the least settings we need to get started, after this we can customize after need.
# SearXNG settings
use_default_settings: true
general:
debug: true
instance_name: "SearXNG"
search:
safe_search: 2
autocomplete: 'duckduckgo'
formats:
- html
- json
server:
# Is overwritten by ${SEARXNG_SECRET}
secret_key: "ultrasecretkey"
limiter: false
image_proxy: true
# public URL of the instance, to ensure correct inbound links. Is overwritten
# by ${SEARXNG_BASE_URL}.
# base_url: http://example.com/location
port: 8888
bind_address: "0.0.0.0"
valkey:
# URL to connect valkey database. Is overwritten by ${SEARXNG_VALKEY_URL}.
url: false
Generate a unique key
sudo sed -i "s|ultrasecretkey|$(openssl rand -hex 32)|g" /etc/searxng/settings.yml
Now we will sudo into our searxng account.
sudo -H -u searxng -i
Next we need to fetch the code.
git clone "https://github.com/searxng/searxng" "/usr/local/searxng/searxng-src"
Creating a python environment creates an wrapper that makes it possible for us to install packages that aren't system native.
python3 -m venv "/usr/local/searxng/searx-pyenv"
source /usr/local/searxng/searx-pyenv/bin/activate
Next we enter the code directory, install some extra dependencies and also the dependencies defined by the project.
cd "/usr/local/searxng/searxng-src"
pip install -U pip setuptools wheel pyyaml msgspec
pip install --use-pep517 --no-build-isolation -e .
Now we test the application by setting an environment variable for the settings file and then starting the application.
export SEARXNG_SETTINGS_PATH="/etc/searxng/settings.yml"
python searx/webapp.py
After ensuring the application runs correctly we will exit the searxng user account and return to our logged in user with sudo access. We need now to create a start script.
sudo vi /usr/local/searxng/searxng.sh
The script does pretty much exactly the steps we did earlier to test our application.
#!/bin/bash
source /usr/local/searxng/searx-pyenv/bin/activate
cd /usr/local/searxng/searxng-src
python searx/webapp.py 2>&1
Make the script executable and give the user and group permissions to searxng.
sudo chmod +x /usr/local/searxng/searxng.sh
sudo chown searxng:searxng /usr/local/searxng/searxng.sh
Lastly we will create a service by editing:
sudo vi /etc/systemd/system/searxng.service
The service definition below is pretty simple, setting environment variable, pid file and script to run to start the application.
[Unit]
Description=SearXNG service
Wants=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Environment="SEARXNG_SETTINGS_PATH=/etc/searxng/settings.yml"
RuntimeDirectory=searxng
Type=simple
User=searxng
Group=searxng
TimeoutStartSec=0
Restart=always
RestartSec=10s
PIDFile=/run/searxng/searxng.pid
ExecStart=/usr/local/searxng/searxng.sh
Reload the daemon configuration, start and enable the service and check status to see that all started correctly.
sudo systemctl daemon-reload
sudo systemctl start searxng
sudo systemctl enable searxng
sudo systemctl status searxng
Your searxng service should now be available on port 8888 on the newly installed machine.
7 comments
Great instructions. Very helpful. And accurate and up to date unlike many of the other solutions online right now.
One big suggestion though.
In the /etc/searxng/settings.yml file, you specify this:
secret_key: “j1yi1ePRLP48PWBYSn9ht”
The secret_key should be unique per instance. People should generate their own, not use yours.
I would recommend the following:
1. Instead of the above line, put this one in the yml file instead:
secret_key: “ultrasecretkey”
2. Save the yml file.
2. Once the yml file has been saved, then run this command in order to replace “ultrasecretkey” with a unique random number.
sudo sed -i “s|ultrasecretkey|$(openssl rand -hex 32)|g” /etc/searxng/settings.yml
This approach provides much more privacy and security.
Great suggestion.
I’ve changed the script, I’m not using that, just wanted to give an example of a complex password but generating one is probably better.
Excellent. Thanks for the reply and updating the script.
Warm wishes for a joyful holiday season and new years.
Thank you for an excellent video and this guide!
I expecienced an issue (error) when running: pip install –use-pep517 –no-build-isolation -e .
I did this as a fix (in the python environment): pip install -U typing-extensions.
Then I ran: pip install –use-pep517 –no-build-isolation -e .
Just thought I’ll leave this here in case anyone else has the same issue.
Thank you for this guide!
I am getting a ModuleNotFoundError: No Module Named ‘flask’ when checking the status of the service.
I tried to install the flask module, but the error remains persistent.
Do you have any suggestions?
Hi Steve.
That is strange, I have not seen this. I would try checking out a tag instead and see if that will help.
Best regards
Daniel
I love when people make articles like this! Honestly, scrolling docs is one thing but catering the build process to your exact situation is lovely. Too many times there’s a generalized “Linux Terminal Install” command then whoops I chose a ill fitted distro and it’s a sort of debug hell of what went wrong. Mind you… I am actually having issues using this guide start to end because of my lack of debian savy or whatnot but hey I’m just glad you make it regardless.
Cheers! Keep doing you.
Perhaps a bookmark is in order.
(:3)