May 2, 2023 6 min read

How to Install Asterisk on Ubuntu 22.04

Install Asterisk on Ubuntu 22.04 with our step-by-step tutorial. It's a famous open-source PBX platform useful for businesses and enterprises.

Install Asterisk on Ubuntu 22.04
Table of Contents

Choose a different version or distribution

Introduction

Before, we begin talking about how to install Asterisk on Ubuntu 22.04. Let's first understand – What is Asterisk?

Asterisk is a very famous and open-source PBX platform that powers IP PBX systems, conference servers, and VoIP gateways. It is being used worldwide by small businesses to huge enterprises.

It has many useful features like music on hold, call queuing, interactive voice response, conference calling, and voicemail.

In this tutorial, you will install Asterisk on Ubuntu 22.04. We will also address few FAQs related to Asterisk installation.

Here are some benefits of using Asterisk:

  1. Cost-effective: Asterisk is open-source, which means it’s free to use and can be modified to fit specific needs. This can make it an affordable alternative to commercial communication solutions.
  2. Flexibility: Asterisk can be integrated with a variety of technologies and programming languages, including PHP, Python, and Perl. This means developers can build a wide range of communication applications tailored to their specific needs.
  3. Customizability: Asterisk is highly customizable and can be configured to work with almost any type of telephony hardware or software. This makes it easy to integrate existing systems with new applications.

Prerequisites

  1. Make sure to log in as a user with sudo privileges.
  2. 1 GB RAM
  3. or more CPU cores
  4. Ubuntu 22.04 installed on your system

Step 1 – Download Asterisk (Method 1)

1) It is recommended to update your system packages before installing Asterisk.

sudo apt-get update
sudo apt-get upgrade

2) Now, install the build-essentials and dependencies using the following command:

sudo apt-get install build-essential

sudo apt-get install git-core subversion wget libjansson-dev sqlite autoconf automake libxml2-dev libncurses5-dev libtool

Download Asterisk (Method 2)

1) Download Asterisk source in the /usr/src directory. It is the common location to place source files. Now, change the directory using the following command:

cd /usr/src/

2) Download the latest version of Asterisk using the below wget command:

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

3) After the download is completed, extract the tarball with the following command:

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

4) Before continuing with further steps. Make sure to change to the Asterisk source directory by:

cd asterisk-*/

Step 2 – Install Asterisk Dependencies

1) This script will download the MP3 sources, they are necessary to build the MP3 module and useful for MP3 files on Asterisk:

sudo contrib/scripts/get_mp3_source.sh

2) You will then use install_prereq script to resolve all the dependencies on your Ubuntu system:

sudo contrib/scripts/install_prereq install

The above script will install all necessary packages on successful completion. Next, it will print the below message:

Ouput

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

Step 3 – Install Asterisk

1) The configure script will perform various checks to make sure that all the dependencies on your system are present. You can start the script by typing:

sudo ./configure

After successful completion, you will see the below output:

configure-asterisk

2) Then select the modules you want to compile and install. Next, access the Menu-select system by typing the following command:

sudo make menuselect

3) After, downloading MP3 source files, you will need to tell Asterisk to build the MP3 module. Do it by selecting format_mp3:

asterisk-mp3

4) When you are done with this, then press F12 to save and exit or switch to the Save and Exit button. Next, press Enter. You will be able to start the compilation process. Do it using the make command, by:

sudo make -j2
👉
The compilation may take some time. It will depend upon your system. You can modify the -j flag as per the number of cores in your processor.

You will see the following message:

compile-asterisk

5) The next step is to install Asterisk and its modules by running the following command:

sudo make install

Once the installation is complete, then the script will display the below message:

install-asterisk

6) Now, after Asterisk installation, you will install sample configuration files.

Install either generic configuration files, with reference documentation by:

sudo make samples

Or install the basic PBX configuration files, by:

sudo make basic-pbx

8) Install the Asterisk init script using the following command:

sudo make config

9) It's good to run ldconfig to update the shared libraries cache:

sudo ldconfig

Step 4 – Create Asterisk User

1) By default, Asterisk runs as a root user. For security purposes, you will have to create a new system user as well as configure Asterisk to run as a new user. To create a new system user, run the below command:

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

2) To configure Asterisk to run as asterisk user, open /etc/default/asterisk file. Further, uncomment the below 2 lines:

AST_USER="asterisk"
AST_GROUP="asterisk"

3) Next, add asterisk user to the dialout as well as to audio groups, using the following command:

sudo usermod -a -G dialout,audio asterisk

4) You will also need to change the ownership and permissions of all asterisk files and directories, after which 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

Step 5 – Start Asterisk

1) Now, you can start the Asterisk service. Do it with the following command:

sudo systemctl start asterisk

2) You will need to verify that Asterisk is running. So, connect to the Asterisk command-line interface (CLI) by:

sudo asterisk -vvvr

You will see the below default Asterisk CLI prompt:

asterisk-cli

3) The next is to enable the Asterisk service to start on boot using the following command:

sudo systemctl enable asterisk

Step 6 – Configure the Firewall

1) The firewall will secure your server from unwanted traffic. By default, SIP uses the UDP port 5060, to open the port run:

sudo ufw allow 5060/udp

2) If you will enable the real-time Protocol, then you also need to open the port range, by:

sudo ufw allow 10000:20000/udp

Now, you can easily adjust the firewall as per your need.

FAQs to Install Asterisk on Ubuntu 22.04

Is it possible to run Asterisk without special hardware?

Yes, PSTN hardware like Digium cards or ISDN adapters is not a requirement. For some applications, like the conferencing application, you need hardware to get timer support, but that’s possible in many ways. Asterisk works well as a VOIP and voicemail server with SIP, MGCP, IAX, and H.323 support both with and without PSTN connectivity.

How do I dial from the CLI?

You’ll need chan_oss for that. chan_oss provides a “dial” command from the CLI that connects the soundcard (via chan_oss) to the outgoing line. By including the module chan_oss, you’ll find a new “dial” command on the CLI.

What packages are required to install Asterisk on Ubuntu 22.04?

The only package required to install Asterisk on Ubuntu 22.04 is asterisk, which can be installed using the apt package manager.

Is there a graphical user interface (GUI) for Asterisk?

Yes, Ubuntu 22.04 comes with a built-in GUI for managing Asterisk called FreePBX.

What programming languages can I use with Asterisk on Ubuntu 22.04?

Asterisk can integrate with many programming languages, including PHP, Python, and JavaScript.

Conclusion

We hope this detailed tutorial helped you to install Asterisk on Ubuntu 22.04.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.