How to Setup Asterisk PBX on Ubuntu Linux

This brief tutorial shows students and new users how to install Asterisk on Ubuntu 18.04 | 18.04 server.

For the uninitiated, Asterisk is an open-source, widely used private branch exchange (PBX) platform. Individuals, businesses, and governments across the globe are using it to power their VoIP and conferencing infrastructures.

Asterisk provides a complete set of features that include voicemail, interactive voice response, conference calling, music on hold, call queuing, call recording, and many more that I can’t list here.

If you need an open-source PBX platform to run your business or institution, then look no further than Asterisk. This post should come in handy and get you started and quickly.

For more about Asterisk, please visit its homepage.

To get started with installing Asterisk, please follow the steps below:

Download and Install Asterisk

To install Asterisk, you’ll have to have some basic packages installed. To install these packages, run the commands below:

sudo apt update
sudo apt install wget build-essential subversion

Since we’re going to be manually downloading Asterisk packages, let’s put them in the system /usr/src directory since it’s where most source files are stored.

To do that, change into the /usr/src directory and download Asterisk.

To get the latest version of Asterisk, the visit is package repository here. Then replace the version number in the commands below with the latest.

At the time of this wiring, the current version is 17.

cd /usr/src/
sudo wget

Once the Asterisk file is downloaded, extract it, then change it into its directory and run the installation script that will download and install all dependencies, including MP3 modules.

sudo tar zxf asterisk-17-current.tar.gz
cd asterisk-17.*/
sudo contrib/scripts/
sudo contrib/scripts/install_prereq install

After running the commands above, the script should download and install all packages. then prints out a successful message similar to the one below:

Current status: 27 (-2) upgradable.
## install completed successfully

Next, run the commands below to configure and perform some checks and validate that all is well.

sudo ./configure

After successful completion, it should display similar lines as below:

configure: Menuselect build configuration successfully completed

            .$7$7.          .7$$7:.    
          .$$:.                 ,$7.7   
        .$7.     7$$$$           .$$77  
     .$$.       $$$$$            .$$$7 
    .7$   .?.   $$$$$   .?.       7$$$.
   $.$.   .$$$7. $$$$7 .7$$$.      .$$$.
 .777.   .$$$$$$77$$$77$$$$$7.      $$$,
 $$$~      .7$$$$$$$$$$$$$7.       .$$$.
.$$7          .7$$$$$$$7:          ?$$$.
$$$          ?7$$$$$$$$$$I        .$$$7 
$$$       .7$$$$$$$$$$$$$$$$      :$$$. 
$$$       $$$$$$7$$$$$$$$$$$$    .$$$.  
$$$        $$$   7$$$7  .$$$    .$$$.   
$$$$             $$$$7         .$$$.    
7$$$7            7$$$$        7$$$      
 $$$$$                        $$$       
  $$$$7.                       $$  (TM)     
   $$$$$$$.           .7$$$$$$  $$      

configure: Package configured for: 
configure: OS type  : linux-gnu
configure: Host CPU : x86_64
configure: build-cpu:vendor:os: x86_64 : pc : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : pc : linux-gnu :

After that, you will want to select some modules to compile and install. You can access the menu system using the commands below:

sudo make menuselect

Because we want to use MP3 as our audio format and have already downloaded its module above, choose the format_mp3 as shown in the image below:

   ┌────────────────────────┤ Asterisk Module and Build Option Selection ├────────────────────────┐
   │                                                                                              │ 
   │   Add-ons (See README-addons.txt)        --- Extended ---                                  ↑ │ 
   │   Applications                       [ ] chan_mobile                                       ▒ │ 
   │   Bridging Modules                   [ ] chan_ooh323                                       ▒ │ 
   │   Call Detail Recording              [*] format_mp3                                        ▒ │ 
   │   Channel Event Logging              [ ] res_config_mysql                                  ▒ │ 
   │   Channel Drivers                        --- Deprecated ---                                ▒ │ 
   │   Codec Translators                  [ ] app_mysql                                         ▒ │ 
   │   Format Interpreters                [ ] cdr_mysql                                         ▮ │ 
   │   Dialplan Functions                                                                       ▒ │ 
   │   PBX Modules                                                                              ▒ │ 
   │   Resource Modules                                                                         ▒ │ 
   │   Test Modules                                                                             ▒ │ 
   │   Compiler Flags                                                                           ▒ │ 
   │   Utilities                                                                                ▒ │ 
   │   AGI Samples                                                                              ↓ │ 
   │                                                                                              │ 
   │  MP3 format [Any rate but 8000hz mono is optimal]                                            │ 
   │                                                                                              │ 
   │      Depends on: N/A                                      ┌───────────────┐   ┌──────────┐   │ 
   │         Can use: N/A                                      │  Save & Exit  │   │   Exit   │   │ 
   │  Conflicts with: N/A                                      └───────────────┘   └──────────┘   │ 
   │   Support Level: extended                                                                    │ 

   toggles selection |  saves & exits |  exits without save

Once you are finished, press F12 to save and exit, or switch to the Save and Exit button and press Enter.

When you’re all done, run the commands below to start the compilation process.

sudo make -j2

The compilation may take some time, depending on your system. The -j flag with the number represents the number of CPUs on your server. If your server has more than 2 CPU cores, then change it to that.

Once the packages and modules are compiled, you should see a success message similar to the one below:

 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, and +
 + can be installed by running:              +
 +                                           +
 +                make install               +

After compiling the above, you can finally install Asterisk by running the commands below:

sudo make install

After the installation, you should see a similar message as below:

 +---- Asterisk Installation Complete -------+
 +                                           +
 +                                           +
 + Asterisk has successfully been installed. +
 + If you would like to install the sample   +
 + configuration files (overwriting any      +
 + existing config files), run:              +
 +                                           +
 + For generic reference documentation:      +
 +    make samples                           +
 +                                           +
 + For a sample basic PBX:                   +
 +    make basic-pbx                         +
 +                                           +
 +                                           +
 +-----------------  or ---------------------+
 +                                           +
 + You can go ahead and install the asterisk +
 + program documentation now or later run:   +
 +                                           +
 +               make progdocs               +
 +                                           +
 + **Note** This requires that you have      +
 + doxygen installed on your local system    +

Installation is complete.

You can now begin configuring your system. First, you may want to add some sample data to help you with configuring your platform. To do that, run the commands below:

sudo make samples
sudo make basic-pbx

Finish the configuration by running the commands below:

sudo make config
sudo ldconfig

Creating Asterisk User

We don’t want to have an Asterisk running as the root user. So let’s create a dedicated user that will run as an Asterisk.

To do that, run the commands below to create an account and a group called asterisk.

sudo addgroup --quiet --system asterisk
sudo adduser --quiet --system --ingroup asterisk --no-create-home --disabled-password asterisk

After creating the account above, open the /etc/default/asterisk file and make the highlighted changes below:

sudo nano /etc/default/asterisk

Then make the highlighted changes below and save the file.

# Startup configuration for the Asterisk daemon

# Uncomment the following and set them to the user/groups that you
# want to run Asterisk as. NOTE: this requires substantial work to
# be sure that Asterisk's environment has permission to write the
# files required  for  its  operation, including logs, its comm
# socket, the asterisk database, etc.

After that, add an asterisk user to the dialout and audio groups:

sudo usermod -a -G dialout,audio asterisk

Next, change permissions on all of the Asterisk files and directories to make their users owners.

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

Starting Asterisk

At this point, all is done. Run the commands below to enable and start the Asterisk service.

sudo systemctl enable asterisk
sudo systemctl start asterisk

To verify that Asterisk is running, run the commands below:

sudo asterisk -vvvr

You’ll see the default Asterisk CLI prompt:

Asterisk 17.2.0, Copyright (C) 1999 - 2018, Digium, Inc. and others.
Created by Mark Spencer <>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
Connected to Asterisk 17.2.0 currently running on ubuntu1804 (pid = 14491)

Most Ubuntu installations don’t have a firewall enabled. If you do, you’ll want to allow the ports below.

By default, SIP uses the UDP port 5060. Open the following port.

sudo ufw allow 5060/udp

For Real-Time Protocol (RTP) open the following port range:

sudo ufw allow 10000:20000/udp

That’s it!


This post showed you how to install and configure Asterisk on Ubuntu 18.04 | 16.04. If you find any error above, please use the form below to report it.