How to Install and Configure Asterisk Server from Source on Ubuntu

· >
Learn to Install Asterisk on Ubuntu

Install and Configure Asterisk Server from Source on Ubuntu

In this article we shall learn to install & configure Asterisk Server on Ubuntu machine, but before diving into the nitty gritty lets talk about what is Asterisk and what are its uses cases?

What is Asterisk Server?

Asterisk is an open-source PBX platform for developing communications applications such as conference call servers and VoIP gateways. Asterisk is freely distributed using General Public License (GPL). It is used by individuals, small businesses, large enterprises, and governments worldwide.
Asterisk features include voicemail, music on hold, conference calling, call queuing, call recording, Interactive Voice Response (IVR), SMS messaging, and more.

What Can I Do With Asterisk Server?

You can use Asterisk Server for following purposes.

  • Voice Calls
  • Voicemail
  • Conference Call Bridges
  • Call Recording
  • IVR (Interactive Voice Response)
  • Automated Call Distributor

Resolving Dependencies

In this tutorial we shall install Asterisk from source means we shall download the source code and compile it ourselves. First we need to install dependencies or tools required to download, install & build Asterisk on our server.

$ sudo apt update
$ sudo apt install wget build-essential git autoconf subversion pkg-config libtool

DAHDI & LibPRI Installation

DAHDI (Digium Asterisk Hardware Digital Interface) is a set of drivers and utilities that allows Asterisk to communicate with analog and digital telephones. The LibPRI library allows Asterisk to communicate with ISDN connections. Libpri is a C implementation of the Primary Rate ISDN specification. libpri is distributed under the terms of the GNU General Public License, which permit its use and linking with other GPL’d software only. If you have hardware installed on your server that can interface with Digital or Analog Telephone Line then you can install these libraries otherwise skip this step.

Steps to install DAHDI:

$ cd /usr/src
$ sudo git clone git://git.asterisk.org/dahdi/linux dahdi-linux
$ cd dahdi-tools
$ sudo autoreconf -i
$ sudo ./configure
$ sudo make install && make install-config
$ sudo dahdi_genconf modules

Steps to Install libPRI libraries:

$ cd /usr/src/
$ sudo git clone git://git.asterisk.org/dahdi/tools dahdi-tools
$ cd libpri
$ sudo make && make install


Download and Installing Asterisk

As stated earlier that in this tutorial we shall install Asterisk from its source code and then compile it locally.

$ cd /usr/src/
$ sudo git clone -b 18 https://gerrit.asterisk.org/asterisk asterisk-18

At the time of publishing this article, Asterisk version is 18.x, so watch out for current version and update it accordingly before cloning.

Next we shall download MP3 audio files as these are required to build MP3 modules. Once script “install_prereq” is downloaded execute it to install.

$ cd asterisk-18/
$ sudo contrib/scripts/get_mp3_source.sh
$ sudo contrib/scripts/install_prereq install

Now we have downloaded & installed the script, we need to run “./configure” to run several checks to make sure all dependencies are present on our server.

$ ./configure

Next we need to build MP3 Module in MP3 format which can be done by accessing menuselect as follows:

$ sudo make menuselect

“Asterisk Module & Build Option Selection” Window will open up, by using arrow keys, take the selector to format_mp3 and press space bar to select it. Then press tab button several times until “Save & Exit” button is selected. Press Enter to continue.

Then to start the compilation & installation process execute below command, please have patience as it may take time.

$ sudo make && make install

Asterisk has now been installed on your ubuntu server, last steps to install the basic PBX configuration files and Asterisk Init files.

$ sudo make basic-pbx
$ sudo make config

Asterisk User Creation

It is good practice to create application specific users, by default, Asterisk runs with root user. As security best practices, we shall create a system user asterisk “asterisk” with group named ” asterisk”

sudo adduser --system --group --home /var/lib/asterisk asterisk

Now that user has been created we need to program asterisk to use this user to run its process.

sudo nano /etc/default/asterisk

And uncomment following lines from the file, save the changes and close


Add “asterisk” user to other groups audio & dialout group using usermod command ulitlity.

$ sudo usermod -aG dialout,audio asterisk

We also need to change the ownership and permissions of all asterisk files and directories so the user asterisk can access those files:

$ sudo chown -R asterisk:  /etc/asterisk /usr/lib/asterisk /var/{lib,log,run,spool}/asterisk 
$ chmod -R 750 /etc/asterisk /usr/lib/asterisk /var/{lib,log,run,spool}/asterisk

Starting & Enabling Asterisk Service

Now Asterisk is fully installed and ready to run, so lets start the service and to make sure that the service autmatically starts on bootup execute as follows:

$ sudo systemctl start asterisk
$ sudo systemctl enable asterisk

Open Ports on Your Server

For asterisk to make connections outside the network to register with SIP provider, you need to open up ports on your server. By default Ubuntu comes with UFW firewall, if you want to know more about UFW firewall you can read our article here.

Asterisk uses SIP protocol which uses UDP port 5060, so we need to open UDP port 5060 on our server as follows.

$ sudo ufw allow 5060/udp

if you have any other service enabled in asterisk, make sure to open port accordingly.


That’s it, we have successfully installed Asterisk on our Ubuntu server from source. I hope this has been informative for you and I would like to thank you for viewing.

Notify of
Inline Feedbacks
View all comments