How To Install Asterisk On Ubuntu

How To Install Asterisk On Ubuntu

Reading time1 min
#VoIP#Telecommunications#Ubuntu#Asterisk#Linux#PBX

Step-by-Step Guide to Installing Asterisk on Ubuntu for Robust VoIP Systems

Enterprise telephony platforms rarely allow customization at the source level. That's where deploying Asterisk, compiled from source, on Ubuntu pays dividends—granular PBX control, full module selection, and regular security patching. If you want exacting control over SIP, real-time call logic, or integration with business systems, start as root and don’t rely on distribution packages.


Requirements

  • Ubuntu 20.04 LTS or newer, bare metal or virtualized.
  • Root (or sudo) access.
  • Reliable internet connection.
  • Working familiarity with Linux tools and networking.

1. Update the System

Outdated dependencies cause unpredictable compiler errors and odd Asterisk runtime problems, especially with audio codecs.

sudo apt update && sudo apt upgrade -y

No reboot needed unless the kernel is updated. For production, schedule accordingly.


2. Install Prerequisites

Required for building Asterisk 19+ and usual add-ons (SIP, Zulu, AMI, etc.):

sudo apt install -y build-essential libxml2-dev libncurses5-dev uuid-dev libjansson-dev libssl-dev libsqlite3-dev wget

If you get package errors, ensure your /etc/apt/sources.list is uncorrupted. For custom channel drivers (pjsip, etc), additional -dev libraries may be needed. If you omit libjansson-dev, AMI/ARI JSON features break.


3. Acquire and Unpack Asterisk Source

Latest Asterisk source offers bug fixes and improved protocol support. Distributions lag far behind:

cd /usr/src/
sudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-19.10.2.tar.gz
sudo tar xvf asterisk-19.10.2.tar.gz
cd asterisk-19.10.2

Always verify checksums for compliance-critical deployments.


4. Resolve Additional Dependencies

The convenience script below detects the local distro and installs further dependencies, including those optional features that basic packages might miss:

sudo contrib/scripts/install_prereq install

Watch the output—if modules you care about will not be built due to missing -dev packages, install them before building.


5. Configure and Compile

First configure for your environment:

sudo ./configure

Don’t ignore configuration errors—resolve missing libraries explicitly. For module selection:

sudo make menuselect

Example: For classic SIP (not PJSIP), enable chan_sip. If compiling for minimal attack surface, deselect CDR backends or codecs you don't use.

Then compile and install:

sudo make -j$(nproc)
sudo make install
sudo make samples
sudo make config

Sidenote: If compiling on modest hardware or in virtualized CI/CD runners, temporarily bump swap or expect longer build times.

DAHDI kernel modules (make dahdi_install, make dahdi_config) only make sense if integrating with analog/digital telephony hardware. For most VoIP-only deployments, you can skip these (expect warning messages about DAHDI at startup—ignore if not running hardware cards).


6. Secure Service Execution

Asterisk should never run as root.

sudo adduser --disabled-password --gecos "Asterisk User" asterisk

Enforce ownership on runtime directories—forgetting /var/run/asterisk leads to failed startups:

sudo chown -R asterisk:asterisk \
  /var/lib/asterisk \
  /var/log/asterisk \
  /var/run/asterisk \
  /etc/asterisk \
  /usr/lib/asterisk/modules

Edit /etc/default/asterisk:

AST_USER=asterisk
AST_GROUP=asterisk

Note: Permissions issues surface as cryptic “Cannot connect to Asterisk” or socket errors. Always fix ownership first.


7. Enable and Launch the Asterisk Service

Enable systemd unit, then start. Monitor logs for immediate failure. Typical symptom of past missteps:

[FAILURE] asterisk.service: Failed with result 'exit-code'.

To initialize:

sudo systemctl daemon-reload
sudo systemctl enable asterisk
sudo systemctl start asterisk
sudo systemctl status asterisk

8. Interact with the Asterisk CLI

Start the CLI interface (the more 'v's, the more verbose):

sudo asterisk -rvvvvv

Confirm version and active modules:

*CLI> core show version

A healthy load displays something like:

Asterisk 19.10.2 built by builduser @ hostname on a Linux x86_64 platform

CLI is critical for troubleshooting failed SIP registrations, dialplan syntax errors, or codec negotiation failures.


9. Configuration File Primer

Asterisk doesn’t do much out-of-the-box; writing effective dialplans is what separates trivial installs from production PBX.

  • /etc/asterisk/sip.conf – SIP endpoint definitions.
  • /etc/asterisk/extensions.conf – Call flow (“dialplan") logic.
  • /etc/asterisk/voicemail.conf – Voicemail parameters.

Example: Single SIP endpoint connecting to a softphone client:

[1001]
type=friend
host=dynamic
secret=8hDdyuY9zXUaR52y ; replace with long random string
context=internal_calls
disallow=all
allow=ulaw
nat=auto_force_rport,auto_comedia
qualify=yes
callerid="User1001" <1001>

Dialplan snippet for a basic extension:

[internal_calls]
exten => 1001,1,Answer()
 same => n,Dial(SIP/1001)
 same => n,Hangup()

Always reload after modifying configs:

*CLI> dialplan reload
*CLI> sip reload

Note: Don't skip voicemail setup in voicemail.conf or users will get “mailbox does not exist” errors.


10. Extra: Backups and Defense in Depth

  • Back up configs: cp -r /etc/asterisk /etc/asterisk.bak_$(date +%F)
  • Restrict SIP UDP ports to trusted IPs in firewall (e.g., ufw allow from <IP> to any port 5060 proto udp).
  • Disable unused modules in modules.conf.

Known Issues and Side Notes

  • If systemctl start fails, check logs under /var/log/asterisk/messages and journalctl -u asterisk.
  • Ubuntu’s AppArmor can block module loads; if you see denied operations, check /var/log/syslog.
  • Active use of DAHDI may require custom kernel modules—expect version mismatches between kernel and DAHDI occasionally after Ubuntu security updates.
  • For cloud VM deployments (AWS, GCP): Beware network interface renaming (ensuring SIP binds to correct address).
  • If experimenting, snapshot your VM prior to major upgrades—undoing broken config changes is faster this way.

Final Notes

You now have a flexible, production-grade Asterisk PBX, installed from clean source on Ubuntu 20.04+, with none of the limitations of aging package repositories. Configuration is everything; stock samples are only a starting point.

For complex deployments—multiple trunks, realtime databases, external authentication, or PCI-compliant call recording—expect additional security hardening and integration layers.

Common pitfalls: permissions misconfiguration, missing dependencies for desired codecs, network firewalls breaking NAT traversal.

Not perfect: The asterisk.org “install_prereq” script covers most cases, but not all distribution idiosyncrasies. Don’t hesitate to review build logs and Google errors verbatim.


Non-obvious tip: Use make uninstall before re-installing a different source version to avoid orphaned modules causing loader failures.

For real-world debugging, start Asterisk with full verbosity and log level 4 (-vvvvv) and monitor /var/log/asterisk/full during registration attempts.


If you encounter build, startup, or interoperability errors—capture logs and test with bare minimal configs. That usually exposes root causes faster than chasing symptoms.