How to Install Asterisk 18 on Ubuntu 20.04

Asterisk is a popular open-source PBX framework for VoIP gateway development. It is an online telephone solution used by individuals, small and large businesses, enterprises, and various governments.

Asterisk uses a VoIP protocol to make calls over the internet using the TCP/IP instead of the traditional land telephone line. Its features include voicemail, music on hold, conference calling, call queuing, call recording, interactive voice response, SMS messaging, automatic call distribution, and more. Asterisk can be installed on multiple operating systems, including Linux, NetBSD, macOS, and Solaris, among others.

In this tutorial, we learn how to install Asterisk 18 on Ubuntu 20.04.


In Ubuntu repositories, we can find the package Asterisk, but it's an older version. To get the latest version you need to install Asterisk from the source.

First, update your Ubuntu system:

$ sudo apt update

Next, install the required packages needed to compile the Asterisk from the source:

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

Installing DAHDI and LibPRI 

DAHDI is an addition of tools that allows Asterisk to communicate with analog and digital telephones. The LibPRI library is used to communicate with ISDN connections. If you don’t need these libraries, you can ignore this section.

$ sudo git clone -b next git:// dahdi-linux
$ cd dahdi-linux
$ sudo make
$ sudo make install
$ cd ..
$ sudo git clone -b next git:// dahdi-tools
$ cd dahdi-tools
$ sudo autoreconf -i
$ sudo ./configure
$ sudo make install
$ sudo make install-config
$ sudo dahdi_genconf modules

Run the following commands to compile and build LibPRI:

$ cd ..
$ sudo git clone libpri
$ cd libpri
$ sudo make
$ sudo make install

Install Asterisk on Ubuntu

First, clone the Asterisk source code repository (this may take some time):

$ sudo git clone -b 18 asterisk-18

At the time of writing this tutorial, the latest version of Asterisk was 18.7.2 which we are going to compile and install.

Next, download the MP3 sources using shell script which is required to build the MP3 module and use MP3 files on Asterisk:

$ sudo contrib/scripts/

Run the install_prereq script to install the necessary dependencies (this step will also take some time):

$ sudo contrib/scripts/install_prereq install

In the middle of the process, you will be prompted to input your regional area telephone code:

Input regional area telephone code

When it completes, the output should be:

Processing triggers for libglib2.0-0:amd64 (2.64.6-1~ubuntu20.04.4) …
Processing triggers for libc-bin (2.31-0ubuntu9.2) …
Processing triggers for systemd (245.4-4ubuntu3.13) …
Processing triggers for man-db (2.9.1-1) …
Processing triggers for install-info (6.7.0.dfsg.2-5) …
Setting up libgmime-2.6-dev (2.6.23+dfsg1-4) …
Setting up libgmime-3.0-dev:amd64 (3.2.7-1) …

## install completed successfully

Now we need to check if all of the dependencies on your system are present in order to compile the source code. Next, run the following command:

$ sudo ./configure

In the end, you will be greeted with a nice ASCII Asterisk logo.

Next, select the modules you wish to compile and install. To access menuselect, type the following:

$ sudo make menuselect
Asterisk module and build option selection

Select the “format_mp3” option in the menu to build the MP3 module. Navigate using the arrow keys then press Enter to select the option. Select any other option you wish to enable. Now press F12 to save and exit the screen.

Select format_mp3 module

You should see a similar terminal output:

menuselect changes saved!
make[1]: Leaving directory '/home/linoxide/asterisk-18'

To start compiling the source code, run the make command:

$ sudo make -j2

Depending on how many CPU cores your computer has, you can adjust the -j parameter to the number of cores your PC has to speed up the compilation time.

If everything was successful, you should get:

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

Once the compilation is completed, install Asterisk and its modules by typing:

$ sudo make install

You can install the generic configuration files:

$ sudo make samples

Also, install the basic PBX configuration files:

$ sudo make basic-pbx

Lastly, run the following to install the Asterisk init script and update the shared libraries cache:

$ sudo make config

$ sudo ldconfig

Create Asterisk User

For security reasons, it's advised to create a non-root user to run Asterisk. We’ll create a new system user that Asterisk will run as. Run the following command to create the new user named asterisk:

$ sudo adduser --system --group --no-create-home --gecos "Asterisk PBX" asterisk

The output should be:

Adding system user asterisk' (UID 114) ... Adding new groupasterisk' (GID 120) …
Adding new user asterisk' (UID 114) with groupasterisk' …

To configure Asterisk to run as the newly created user, open the /etc/default/asterisk file and uncomment the following two lines near the beginning (delete the # in front of the lines):

$ sudo nano /etc/default/asterisk

Next, add the asterisk user to the following groups:

$ sudo usermod -a -G dialout,audio asterisk

We also need to change the ownership and of all asterisk files and folders so that Asterisk can access those files:

$ 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

Running Asterisk

All that's left to do is to start the Asterisk service with the following command:

$ sudo systemctl start asterisk

Verify that Asterisk is running, by connecting to the Asterisk command-line interface (CLI) by typing:

$ sudo asterisk -vvvr

You should see the output similar to this:

Connected to Asterisk GIT-18-804b1987fb currently running on linoxide (pid = 31426)

Now enable the service to start on boot:

$ sudo systemctl enable asterisk

Configure Firewall

If you have a firewall setup, open HTTP ports and ports 5060,5061:

$ sudo ufw allow 5060/udp
$ sudo ufw allow 10000:20000/udp


Congratulations! You have successfully installed and configured the Asterisk server on Ubuntu 20.04

For additional information, you can check the official Asterisk website.

Leave a Comment