Skip to content

⚡ Part 3: Compiling and Packaging Kamailio on Debian 13 (Trixie)

7 min readUpdated: Sep 26, 2026
View as Markdown

Welcome to the third and final installment of our “Debian 13 Packaging & Distribution” series. In the previous parts, we set up our GPG-signed APT repository and compiled the Telephony Server telephony core. Now, we will compile and package Kamailio (v6.1), the high-performance SIP routing engine, from source on Debian 13. Finally, we will publish the resulting modular packages to our custom repository server and perform an end-to-end client installation.


While Debian provides pre-compiled Kamailio packages in its upstream repositories, they are often lagging behind the latest stable upstream branch or missing custom modules. Compiling Kamailio on our own build node gives us:

  1. Access to the Latest Features: Target the stable 6.1 upstream branch.
  2. Custom Modules: Build only the modules we require (e.g., PostgreSQL support, JSON/JWT processing, WebSockets, or TLS).
  3. Optimization: Compile binaries compiled specifically for your deployment target’s processor architecture (e.g., AMD64 vs. ARM64).

🛠️ Phase 1: Environment & Dependency Setup

Section titled “🛠️ Phase 1: Environment & Dependency Setup”

Kamailio has a modular architecture. In order to build database, presence, secure transport, and logging modules, we must install their corresponding development packages.

Terminal window
apt-get update
apt-get install -y \
sudo git build-essential devscripts dpkg-dev equivs fakeroot \
autoconf automake libtool libtool-bin cmake pkg-config \
wget curl unzip python-is-python3 python3-all-dev \
python3-setuptools docbook-xsl xsltproc \
libglib2.0-dev graphviz dh-make

Install the developer libraries required to compile Kamailio’s core modules:

Terminal window
apt-get install -y \
debhelper dh-cmake dh-sequence-cmake bison flex cmake \
default-libmysqlclient-dev docbook-xml docbook-xsl \
erlang-dev libcurl4-openssl-dev libev-dev libevent-dev \
libexpat1-dev libhiredis-dev libjansson-dev libjson-c-dev \
libjwt-dev libldap2-dev liblua5.4-dev libmaxminddb-dev \
libmemcached-dev libmicrohttpd-dev libmnl-dev libmongoc-dev \
libmosquitto-dev libnats-dev libncurses-dev libnghttp2-dev \
libpcre2-dev libperl-dev libphonenumber-dev libpq-dev \
librabbitmq-dev libradcli-dev librdkafka-dev libreadline-dev \
libsasl2-dev libsctp-dev libsecp256k1-dev libsecsipid-dev \
libsnmp-dev libsqlite3-dev libssl-dev libsystemd-dev \
libunistring-dev libwebsockets-dev libwolfssl-dev libxml2-dev \
lynx openssl python3 python3-dev ruby-dev \
unixodbc-dev uuid-dev zlib1g-dev

⚙️ Phase 2: Compiling & Packaging Kamailio

Section titled “⚙️ Phase 2: Compiling & Packaging Kamailio”

We clone Kamailio into /usr/src/kamailio/src. This isolates our build directories and outputs the packaged files in the parent directory (/usr/src/kamailio/), keeping our source tree clean.

Clone the stable 6.1 branch of Kamailio:

Terminal window
mkdir -p /usr/src/kamailio/deb
git clone -b 6.1 https://github.com/kamailio/kamailio.git /usr/src/kamailio/src
cd /usr/src/kamailio/src
# Link native Debian Trixie packaging control files
ln -s pkg/kamailio/deb/trixie debian
# Rename source and binary packages in debian/control to start with sbc-kamailio
# This adds Provides/Conflicts/Replaces to prevent collisions with official Debian packages
python3 -c "
import re, os
content = open('debian/control').read()
# Prefix all occurrences of kamailio with sbc-
content = re.sub(r'(?<!sbc-)kamailio', 'sbc-kamailio', content)
# Split into stanzas, strip whitespace, and inject compatibility directives safely
stanzas = [s.strip() for s in content.split('\n\n') if s.strip()]
new_stanzas = []
for stanza in stanzas:
match = re.search(r'^Package:\s*(sbc-kamailio[^\s]*)', stanza, re.MULTILINE)
if match:
pkg = match.group(1)
orig = pkg[4:] # Remove 'sbc-' prefix
fields = {'Provides': orig, 'Conflicts': orig, 'Replaces': orig}
for field, value in fields.items():
field_pattern = rf'^({field}:\s*)(.*)'
if re.search(field_pattern, stanza, re.MULTILINE):
stanza = re.sub(field_pattern, rf'\1{value}, \2', stanza, flags=re.MULTILINE)
else:
stanza += f'\n{field}: {value}'
new_stanzas.append(stanza)
content = '\n\n'.join(new_stanzas) + '\n'
open('debian/control', 'w').write(content)
# Rename installation files in debian/ EXCEPT for the service unit, init script, and default config
# This ensures that the installed system service and configuration files retain their standard names
for f in os.listdir('debian'):
if 'kamailio' in f and not f.startswith('sbc-'):
if f in ['kamailio.service', 'kamailio@.service', 'kamailio.init', 'kamailio.default']:
continue
new_f = 'sbc-' + f
os.rename(os.path.join('debian', f), os.path.join('debian', new_f))
# Inject dh_installsystemd and dh_installinit overrides in debian/rules
# to direct debhelper to build the packages using the standard name 'kamailio'
rules = open('debian/rules').read()
overrides = '''
override_dh_installsystemd:
\tdh_installsystemd --name=kamailio
override_dh_installinit:
\tdh_installinit --name=kamailio
'''
if 'override_dh_installsystemd' not in rules:
open('debian/rules', 'a').write(overrides)
"
# Update package source name in changelog to match renamed source package
sed -i 's/^kamailio/sbc-kamailio/g' debian/changelog
# Dynamically extract current upstream version from debian/changelog (e.g., 6.1.4)
CURRENT_VER=$(dpkg-parsechangelog -S Version | sed 's/-.*//')
# Add a new custom changelog version entry using dch (use -b to force version check override)
DEBEMAIL="[EMAIL_ADDRESS]" DEBFULLNAME="[YOUR_FULL_NAME]" dch -b -v "${CURRENT_VER}-0+sbc" "Custom compile with sbc-kamailio package rename"

[!TIP] Handling Version Mismatches & Warnings (dch warning): If you specify a static version (e.g., 6.1.0-0+sbc) and dch warns that new version is less than the current version number (6.1.4), the source branch contains newer maintenance updates. Always use the extracted ${CURRENT_VER} or match the exact upstream version (e.g., 6.1.4-0+sbc) to prevent package downgrade conflicts in APT.

[!NOTE] Debian Packaging Link: Linking pkg/kamailio/deb/trixie to the debian directory is a crucial step. Kamailio maintains native, distribution-specific build scripts within its repository. This link instructs dpkg-buildpackage to use the official rules designed specifically for Debian 13.

Create the build config targets:

Terminal window
make cfg

Clean the workspace and trigger compilation:

Terminal window
# Clean packaging workspace
fakeroot debian/rules clean
# Compile binary-only packages without signing metadata
dpkg-buildpackage -us -uc -b -j$(nproc)
# Move all generated packages and build receipts to our deb directory
mv /usr/src/kamailio/*.deb /usr/src/kamailio/deb/
mv /usr/src/kamailio/*.changes /usr/src/kamailio/deb/ 2>/dev/null || true
mv /usr/src/kamailio/*.buildinfo /usr/src/kamailio/deb/ 2>/dev/null || true

The directory /usr/src/kamailio/deb/ will now contain modular packages, including:

  • sbc-kamailio_*.deb: The core binary and routing engine.
  • sbc-kamailio-postgres-modules_*.deb: Database backends (PostgreSQL engine).
  • sbc-kamailio-presence-modules_*.deb: Presence services (SIP SUBSCRIBE/NOTIFY, dialog info).
  • sbc-kamailio-websocket-modules_*.deb: WebSocket engines (SIP-over-WebSockets for WebRTC clients).

🌐 Phase 3: Publishing Kamailio to the Custom Repository

Section titled “🌐 Phase 3: Publishing Kamailio to the Custom Repository”

With our packages compiled and located inside /usr/src/kamailio/deb/, we can push them to our repository server (IP: <YOUR_REPO_IP>) for distribution. From your build node, secure copy the packages directly to the repository upload directory:

Terminal window
scp /usr/src/kamailio/deb/*.deb root@<YOUR_REPO_IP>:/usr/src/
scp /usr/src/kamailio/deb/*.deb root@76.13.102.153:/usr/src/

Log into your repository server over SSH, organize the files into their target component directories, and rebuild the repository signatures:

Terminal window
ssh root@<YOUR_REPO_IP>
# Sort packages into pool components (base, extras, devel, etc.)
CopyPackagesToRepo
# Rebuild package indexes and sign Release signatures
BuildRepoRing2All

The script cleans up older package builds, scans the new packages, updates Packages.gz indexes, and signs the Release logs cryptographically.


🚀 Phase 4: End-to-End Client Installation

Section titled “🚀 Phase 4: End-to-End Client Installation”

To deploy both Kamailio and Telephony Server on a clean Debian 13 (Trixie) server, run these commands:

Run the repository bootstrap script to register the GPG key and APT source configurations:

Terminal window
wget -qO- https://repo.softswitchone.com/apt/setup_repo | bash

Update the local package manager and install Kamailio alongside PostgreSQL and WebSocket modules:

Terminal window
apt-get update
# Install Kamailio and its essential modules
apt-get install -y \
sbc-kamailio \
sbc-kamailio-postgres-modules \
sbc-kamailio-presence-modules \
sbc-kamailio-websocket-modules
# Verify the installation and check the compiled version
kamailio -v

Example Output:

kamailio 6.1.4 (x86_64/linux)

[!NOTE] What to do if a different version is returned?:

  • Newer Point/Patch Release (e.g., 6.1.4, 6.1.5): This is normal and expected when building from the stable maintenance branch 6.1, as it continuously incorporates verified bugfixes and patches.
  • Unexpected / Older Release (e.g., 5.8.x or default Debian upstream version):
    1. Check if the binary was installed from Debian’s official repository instead of your custom repository:
      Terminal window
      apt-cache policy sbc-kamailio
    2. If conflicting packages exist, remove the generic package (apt-get purge kamailio*) and install the custom packages (apt-get install sbc-kamailio sbc-kamailio-postgres-modules ...).
    3. Verify binary path resolution:
      Terminal window
      which kamailio
      /usr/sbin/kamailio -v

Congratulations! You have completed the 3-part Packaging and Repository series. Here is a review of what we built:

  1. Part 1: Deployed an HTTPS-enabled repository server with RSA GPG key signing and automated indexing scripts.
  2. Part 2: Built Telephony Server and its core telephony dependencies (SpanDSP, Sofia-SIP, libks2, etc.) from source, and published them.
  3. Part 3: Compiled Kamailio v6.1 from source using native packaging links and published its modular parts.
  • Version Pinning: On production nodes, configure APT pinning to prevent upstream Debian repositories from overwriting your custom-built packages.
  • Clean Keyring Management: Always distribute the public signing GPG key via /etc/apt/keyrings/ instead of legacy deprecated paths like apt-key add.
  • Sequential Builds: When rebuilding Telephony Server modules, make sure to keep parallel compilation turned off (parallel=1) to prevent build locks.