How to Install Asterisk on Ubuntu 18.04 | 16.04

ubuntu 3344434 640

This brief tutorial shows students and new user how to install Asterisk on Ubuntu 18.04 | 16.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 sets 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:

Step 1: 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 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, visit is package repository here. Then replace the version number in the commands below to the latest.

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

cd /usr/src/
sudo wget

Once Asterisk file is downloaded, extract it, then change 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 a 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 wand 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 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 CPU on your server. If your server has more then 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 above, you can finally install Asterisk by running the commands below:

sudo make install

After the installation, you should see 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 samples 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

Step 2: Creating Asterisk User

We don’t want to have Asterisk running as the root user. So let’s create a dedicated user that will run as 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 asterisk user to the dialout and audio groups:

sudo usermod -a -G dialout,audio asterisk

Next, change permissions on all of Asterisk files and directory to make its users owner.

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

Step 3: Starting Asterisk

At this point all is done. Run the commands below to enable and start 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 installation don’t have 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.

You may also like the post below:


  1. Nice tutorial. It works like a Charm on ubuntu 18.04.3 vmware 15.5 player.

  2. port 5060 not listening
    i use ubuntu 18.04

    root@server:/usr/src/asterisk-17.4.0# netstat -tunlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0* LISTEN 416/sshd
    tcp 0 0* LISTEN 4038/exim4
    tcp6 0 0 :::22 :::* LISTEN 416/sshd
    tcp6 0 0 ::1:25 :::* LISTEN 4038/exim4
    udp 0 0* 21397/asterisk
    udp 0 0* 21397/asterisk
    udp6 0 0 :::33462 :::* 21397/asterisk

    any suggest to enable port 5060

  3. I love this tutorial after wasting two days Finally I got very good tutorial.
    Thanks Alot

    1. Care to share it with me. I have had nothing but trouble. Please contact me if you can

  4. Oliver Behrendt

    Thank you very much, well explained and working at first attempt.
    Thanks Katasun

  5. Hi.
    For those with the 500 error try this:

    sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
    sudo sed -i ‘s/^\(User\|Group\).*/\1 asterisk/’ /etc/apache2/apache2.conf
    sudo sed -i ‘s/AllowOverride None/AllowOverride All/’ /etc/apache2/apache2.conf

  6. Works on first try on Ubuntu Server 20.04. If you do not change anything (which is not neccesary anyway) this tutorial will work perfect. Every step is well-explained, it just works!

  7. What’s the password for the asterisk user?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.