Installing Asterisk from source

In this article, I will give an example of installing Asterisk from source code, for example, I needed it to install a new version of Asterisk on Ubuntu Server 22.04, since Asterisk 18 was installed from the default repository, and there were no modules I needed by default, such as Voicemail.

Switch to the root user:

sudo -i

Install the necessary components to install Asterisk:

apt update
apt install wget build-essential git autoconf subversion pkg-config libtool libedit-dev

Download the archive with the required version of Asterisk and unpack it:

cd /usr/src/
tar -zxvf asterisk-20-current.tar.gz
cd asterisk-20.1.0

You can also download from here:

git clone -b 20 asterisk-20
cd asterisk-20/

Install the necessary components for Asterisk (you may have to run several times):

contrib/scripts/install_prereq install

Let’s prepare the Asterisk code before compilation:


If you suddenly need to re-run configure, then clear the old cache:

make distclean

Run menuselect to select which modules and components to install with Asterisk:

make menuselect

You can install sample configurations:

make samples
make basic-pbx

Install Asterisk autorun script and log rotation script:

make config
make install-logrotate

Build and install Asterisk:

make install

Let’s create an asterisk user and group, and also specify them in the configuration:

groupadd asterisk
useradd -r -d /var/lib/asterisk -g asterisk asterisk
usermod -aG audio,dialout asterisk
chown -R asterisk.asterisk /etc/asterisk
chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk.asterisk /usr/lib/asterisk
nano /etc/default/asterisk
nano /etc/asterisk/asterisk.conf
runuser = asterisk
rungroup = asterisk

nano /etc/logrotate.d/asterisk
create 640 asterisk asterisk

Activate Asterisk autostart at operating system startup and start Asterisk:

systemctl enable asterisk
systemctl start asterisk
systemctl status asterisk.service

An example of connecting to the Asterisk console in debug mode (the more v letters, the more debug data will be displayed):

asterisk -rvv

Module files are located in the /usr/lib/asterisk/modules directory, sound files are usually located in the /var/lib/asterisk/sounds directory, Asterisk plays files of the format that is easiest to process by the CPU, an example can be seen in the table by running the commands:

core show translation
core show translation recalc 60

If you installed PJSIP instead of the SIP module, then for example, instead of the “sip show peers” command, you will need to execute:

pjsip show endpoints

The list of available commands can be viewed as follows:

core show help

See also my articles:
IPTables rules for Asterisk
Installing Asterisk on Ubuntu Server
My other articles about Asterisk

Leave a comment

Leave a Reply