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

Forget one-click installs; installing Asterisk on Ubuntu hands you control over the telephony stack, from configuration to customization—transform your server into a powerful, tailor-made communication hub.

Asterisk powers countless VoIP communications worldwide, and mastering its installation on Ubuntu unlocks a reliable, cost-effective platform for custom telephony solutions essential for modern businesses and developers. Whether you're building an in-house PBX, experimenting with call routing, or developing custom communications apps, Asterisk is the backbone you need.

In this guide, I’ll take you through the essential steps to install Asterisk on Ubuntu from scratch. By the end of this post, you’ll have a clean Asterisk instance ready to configure and customize according to your telephony needs.


What You’ll Need Before We Start

  • A Ubuntu Server or VM running Ubuntu 20.04 LTS or later (this guide uses 20.04).
  • Root or sudo privileges.
  • Internet connectivity for downloading packages.
  • Basic familiarity with Linux command line.

Step 1: Update Your System

Before installing anything, ensure your system packages are up-to-date:

sudo apt update && sudo apt upgrade -y

This minimizes any issues caused by outdated dependencies.


Step 2: Install Required Dependencies

Asterisk depends on multiple packages such as build tools and libraries. Install them with:

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

These include compilation tools and libraries related to XML, SSL encryption, SQLite database support, and JSON parsing – all essential for modern telephony features.


Step 3: Download the Latest Asterisk Source Code

While Ubuntu’s repositories include Asterisk packages, they’re usually outdated. For maximum control and new features, compile from source.

Visit Asterisk’s official downloads page to find the latest stable release. For this guide, we’ll use version 19.10.2 (replace if newer versions are available).

Download with wget:

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

Extract the archive:

sudo tar xvf asterisk-19.10.2.tar.gz
cd asterisk-19.10.2

Step 4: Install Additional Build Tools via contrib/scripts/install_prereq

The Asterisk source includes a script that installs almost all dependencies automatically:

sudo contrib/scripts/install_prereq install

Run this to fulfill any missing prerequisites.


Step 5: Configure and Compile Asterisk

Prepare the build environment:

sudo ./configure

Once configuration completes successfully, choose which modules you want:

sudo make menuselect

In this menu-driven interface you can enable or disable features like chan_sip (for SIP support), codecs, etc. The default selections are fine as a start; just press 'Save & Exit'.

Now compile:

sudo make
sudo make install

Install samples (configuration files):

sudo make samples

And install startup scripts for systemd management:

sudo make config

Finally, ensure DAHDI kernel modules (for telephony hardware) are installed (optional if you use hardware):

sudo make dahdi_install
sudo make dahdi_config

For most pure VoIP setups without analog hardware cards, this can be safely skipped.


Step 6: Set Up User Permissions

Create an asterisk user to run the service securely:

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

Change ownership of folders (especially logs and spool):

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

Edit /etc/default/asterisk file and set AST_USER=asterisk and AST_GROUP=asterisk so that the service runs as this user.


Step 7: Enable and Start Asterisk Service

Reload systemd daemon and start Asterisk service:

sudo systemctl daemon-reload

sudo systemctl enable asterisk

sudo systemctl start asterisk

sudo systemctl status asterisk

If it says active (running), congratulations — your Asterisk server is live!


Step 8: Connect to the Asterisk CLI for Testing

You can interact with your running Asterisk instance via its CLI using:

sudo asterisk -rvvvv

This connects you to real-time logs and commands testing.

Try running:

core show version

You should see your installed version number displayed confirming installation success.

To exit the console type exit.


Step 9: Basic Configuration Files Overview

Configuration files live under /etc/asterisk/. Here are key files you'll want to know initially:

  • sip.conf — Defines SIP endpoints (phones/extensions).
  • extensions.conf — Controls call routing logic.
  • voicemail.conf — Voicemail setup.

For example, add a simple SIP extension entry in /etc/asterisk/sip.conf:

[1001]
type=friend
host=dynamic
secret=supersecretpass1234 ; choose strong password!
context=internal_calls 
disallow=all 
allow=ulaw ; default audio codec 
nat=yes 
qualify=yes 
callerid="User1001" <1001>

And then an extension in /etc/asterisk/extensions.conf under [internal_calls] context:

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

Reload configs in CLI after changes with:

dialplan reload
sip reload 

Wrapping Up

By now you’ve installed a robust VoIP telephony engine directly on your Ubuntu server empowered by full control over every module and setting in your communication stack!

From here you can build out complex dialplans, integrate CRM systems using ARI interfaces, automate call flows with AGI scripts or implement voicemail—Asterisk’s versatility ensures it adapts perfectly whether for small offices or large-scale deployments.

If you want advanced tutorials (setting up trunks with providers or configuring advanced SIP scenarios), stay tuned for upcoming posts!


Final Tip:

Always back up configs before making big changes (cp -r /etc/asterisk /etc/asterisk.bak), test thoroughly in development environments — VoIP environments must be secure and reliable!

Happy hacking your own custom telephony solution!


Feel free to comment if you hit any snags during installation!