Read in 5 minutes

last updated 

How To Install Asterisk on Ubuntu 18.04

Asterisk is the most popular and widely adopted open source PBX platform that powers IP PBX systems, conference servers and VoIP gateways. 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 and much more.

This tutorial will guide you through the steps required to install Asterisk 15 on Ubuntu 18.04.

An older version of Asterisk (version 13) is available in the Ubuntu software repository and can be easily installed with apt install asterisk.

Prerequisites

Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges.

Update your Ubuntu system and install the following packages which are necessary to download and build Asterisk:

sudo apt update && sudo apt upgrade
sudo apt install wget build-essential subversion

Downloading Asterisk

We are going to download Asterisk source in the /usr/src directory which is the common location to place source files, change to the directory with:

cd /usr/src/

Download the latest version of Asterisk 15 by typing:

sudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz

Once the download is completed extract the tarball with:

sudo tar zxf asterisk-15-current.tar.gz

Before continuing with the next steps, make sure you change to the Asterisk source directory by typing:

cd asterisk-15.*/

Installing Asterisk Dependencies

The following script will download the MP3 sources which are required to build the MP3 module and use MP3 files on Asterisk:

sudo contrib/scripts/get_mp3_source.sh

Use the install_prereq script to resolve all of the dependencies on your Ubuntu system:

sudo contrib/scripts/install_prereq install

The script will install all necessary packages and upon successful completion, it will print the following message:

#############################################
## install completed successfully
#############################################

Installing Asterisk

The configure script will perform a number of checks to make sure all of the dependencies on your system are present, start the script by typing:

sudo ./configure

Upon successful completion, you will see the following output:

The next step is to select the modules you want to compile and install. Access the Menuselect system, by typing:

sudo make menuselect

We have already downloaded the MP3 source files and now we need to tell Asterisk to build the MP3 module by selecting format_mp3:

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

Now we can start the compilation process using the make command:

sudo make -j2

The compilation may take some time, depending on your system. You can modify the -j flag according the number of cores your processor.

Once the build process is completed, you will be presented with the following message:

As the message above says, the next step is to install Asterisk and its modules by typing:

sudo make install

Once the installation is finished the script will display the following message:

Now that we have Asterisk installed we need to install the sample configuration files.

Install either the generic configuration files with reference documentation by typing:

sudo make samples

Or install the basic PBX configuration files:

sudo make basic-pbx

The last step is to install the Asterisk init script by typing:

sudo make config

It is also a good idea to run ldconfig to update the shared libraries cache:

sudo ldconfig

Creating Asterisk User

By default Asterisk runs as a root user. For security reasons we will create a new system user and configure Asterisk to run as the newly created user.

To create a new system user named asterisk run the following command:

sudo adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk

To configure Asterisk to run as asterisk user, open the /etc/default/asterisk file and uncomment the following two lines:

/etc/default/asterisk
AST_USER="asterisk"
AST_GROUP="asterisk"

Add the asterisk user to the dialout and audio groups:

sudo usermod -a -G dialout,audio asterisk

We also need to change the ownership of all asterisk files and directories so the user 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

Starting Asterisk

Now that we are all set up, we can start the Asterisk service with the following command:

sudo systemctl start asterisk

To verify that Asterisk is running, connect to the Asterisk command line interface (CLI) by typing:

sudo asterisk -vvvr

You’ll see the default Asterisk CLI prompt:

The last step is to enable Asterisk service to start on boot with:

sudo systemctl enable asterisk

Configuring Firewall

The firewall will secure your server against unwanted traffic.

If you don’t have a firewall configured on your server, you can check our guide about how to setup a firewall with ufw on ubuntu

By default, SIP uses the UDP port 5060, to open the port run:

sudo ufw allow 5060/udp

If you enabled the Real Time Protocol (RTP) then you also need to open the following port range:

sudo ufw allow 10000:20000/udp

Feel free to adjust the firewall according to your need.

Conclusion

In this guide we have shown you how to install the latest Asterisk version from source on your Ubuntu system.

You should now check the Asterisk Documentation and learn more about how to configure and use Asterisk.

If you hit a problem or have a feedback, leave a comment below.