Skip to main content

How to install Asterisk on Linux

Installing Asterisk is no longer the frustration generator that it once was. This article shows you how straightforward the process is now.

Now that you understand the fundamentals of VoIP and the Asterisk platform, you are ready to install and configure Asterisk. At the moment, Asterisk does not officially distribute packages for Linux distributions, so you’ll have to compile Asterisk from source. While that task might sound daunting, the Asterisk maintainers have gone through great lengths to make this process as easy as possible. This article will walk you through both building and starting Asterisk. When you’re done, you will have a functioning Asterisk system that is ready for further configuration.

Note: The instructions below are current as of the time that this was written. I recommend that you always consult the official installation instructions to ensure that you are following the latest recommended procedures.

Building and installing Asterisk

The first step is to download and unzip a current release of Asterisk. You should consult the Asterisk version documentation when making a decision, but generally, you will want to use the latest LTS version. Asterisk versions can be downloaded from the Asterisk website. I use Asterisk 16.6.1 in this tutorial, but the instructions will generally be the same for other versions.

I used /usr/local/src as the base directory to download the source code into:

[root@asterisk-1 ~]# wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz

[root@asterisk-1 src]# tar -xf asterisk-16-current.tar.gz

[root@asterisk-1 src]# cd asterisk-16.6.1/

You’re now ready to install the prerequisites needed to build and run Asterisk. The Asterisk team has made this process as easy as possible by providing an install_prereq script to automatically install the needed dependencies based on your distribution. Below, I’ve run the script in "test" mode, which helpfully prints the exact command you need to run to install dependencies. I then ran the script in "install" mode to actually install the dependencies that are needed:

[root@asterisk-1 asterisk-16.6.1]# cd scripts

[root@asterisk-1 scripts]# ./install_prereq test
#############################################
## test: test mode.
## Use the commands here to install your system.
#############################################
yum install --skip-broken --assumeyes gcc-c++ libedit-devel jansson-devel libuuid-devel sqlite-devel libxml2-devel speex-devel speexdsp-devel libogg-devel libvorbis-devel alsa-lib-devel portaudio-devel libcurl-devel xmlstarlet bison flex postgresql-devel unixODBC-devel neon-devel gmime-devel lua-devel uriparser-devel libxslt-devel openssl-devel mysql-devel bluez-libs-devel radcli-devel freetds-devel jack-audio-connection-kit-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libical-devel spandsp-devel libresample-devel uw-imap-devel binutils-devel libsrtp-devel gsm-devel doxygen graphviz zlib-devel openldap-devel hoard codec2-devel fftw-devel libsndfile-devel unbound-devel subversion bzip2 patch python-devel

[root@asterisk-1 scripts]# ./install_prereq install

Now that the prerequisites have been installed, you can run the configure scripts in preparation for building Asterisk. On my system, I had to install using the bundled version of libjansson, as the version in the repositories was too old. This command below will run configure scripts for Asterisk:

[root@asterisk-1 asterisk-16.6.1]# ./configure --with-jansson-bundled

By default, Asterisk uses the menuselect utility to present you with a graphical list of configuration options. Take the time to review these to get a sense of the many modules and options available in an Asterisk installation:

Image
The Asterisk channel drivers menu.

In my case, I left all of the options the same with one exception: I unselected the chan_sip module in the Channel Drivers menu. The chan_sip module is an older, deprecated SIP channel driver, and you won’t need it in a modern Asterisk environment.

With the configuration script run, you’re ready to build Asterisk from source using make. I’ve shortened the output below to save space, but once make is done running, you will see a success prompt and instructions to run the installation:

[root@asterisk-1 asterisk-16.6.1]# make
   [CC] astcanary.c -> astcanary.o
   [LD] astcanary.o -> astcanary
   [CC] astdb2sqlite3.c -> astdb2sqlite3.o
   [CC] hash/hash.c -> hash/hash.o
   [CC] hash/hash_bigkey.c -> hash/hash_bigkey.o
   [CC] hash/hash_buf.c -> ha

...

Building Documentation For: third-party channels pbx apps codecs formats cdr cel bridges funcs tests main res addons
+--------- Asterisk Build Complete ---------+
+ Asterisk has successfully been built, and +
+ can be installed by running: +
+ +
+ make install +
+-------------------------------------------+

Once the build has completed, you are ready to install Asterisk. As the prompt suggests, this task is easy: Just run make install. I also recommend running make samples (to generate config file samples) and make config (to generate systemd unit files). Again, I have shortened the output below for brevity:

[root@asterisk-1 asterisk-16.6.1]# make install

...

+---- Asterisk Installation Complete -------+
+ +
+        YOU MUST READ THE SECURITY DOCUMENT   +
+                 +
+ 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   +
+-------------------------------------------+

[root@asterisk-1 asterisk-16.6.1]# make samples
[root@asterisk-1 asterisk-16.6.1]# make config

Finally, I found that I had to restore the SELinux context on a few files used by Asterisk in my environment. To do so, I used the commands below:

[root@asterisk-1 asterisk-16.6.1]# restorecon -v /var/lib/asterisk/astdb.sqlite3
[root@asterisk-1 asterisk-16.6.1]# restorecon -rv /var/lib/asterisk/
[root@asterisk-1 asterisk-16.6.1]# restorecon -rv /etc/asterisk/

Note: You might find that additional SELinux tuning is needed in your environment, which is beyond the scope of this article (< if we have an selinux enable sysadmin article, link to it here>). [Note: Add link.]

Congratulations! Asterisk has now been installed and you’re ready to begin configuration. You can now verify your installation by starting the Asterisk service and connecting via the command line as seen below. Be sure to stop the service when you’re done since you won’t have any configuration in place until we set up phones in this series’ next article:

[root@asterisk-1 ~]# systemctl start asterisk
 
[root@asterisk-1 ~]# asterisk -r
Asterisk 16.6.1, Copyright (C) 1999 - 2018, Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
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 16.6.1 currently running on asterisk-1 (pid = 22082)
asterisk-1*CLI> quit
Asterisk cleanly ending (0).
Executing last minute cleanups

[root@asterisk-1 ~]# systemctl stop asterisk

Wrapping up

In this article, you learned how to build and install Asterisk from source. Thanks to the efforts of the Asterisk project, this is a simple and painless experience. You are now ready to begin configuring Asterisk in the next article of this series.

Topics:   Networking   VOIP  
Author’s photo

Anthony Critelli

Anthony Critelli is a Linux systems engineer with interests in automation, containerization, tracing, and performance. He started his professional career as a network engineer and eventually made the switch to the Linux systems side of IT. He holds a B.S. and an M.S. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.