Asterisk is a widely used open-source PBX platform for developing communications applications. Such as conference servers and VoIP gateways. It provides a set of features including, conference calling, call queuing, call recording, voicemail, music on hold, interactive voice response, SMS messaging, and more. In this tutorial you will learn how to install Asterisk on Ubuntu 22.04.
By default, Ubuntu repositories contains an older Asterisk version. We’ll install the latest Asterisk from the source code.
Follow the below steps to install Asterisk on your Ubuntu 22.04 system:
Step 1 – Installing Packages
Install the following packages that are necessary to download and build Asterisk.
You have to install following packages:
sudo apt update
sudo apt install wget build-essential git autoconf subversion pkg-config libtool
Step 2 – Install Asterisk on Ubuntu
Now we will download the latest version of Asterisk from the Asterisk official website using the following command:
cd /usr/src/
sudo git clone -b 20 https://gerrit.asterisk.org/asterisk asterisk-20
Currently, at the time of writing, the latest version of Asterisk is 20.x. After that, change the directory to the extracted directory. Before going ahead, change to the Asterisk source directory:
cd asterisk-20/
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
Next, install other dependencies with the following command:
sudo contrib/scripts/install_prereq install
It will show you a success message as following :
############################################# ## install completed successfully ## #############################################
The configure
script performs several checks to make sure all of the dependencies on your system are present. Run the script by typing:
sudo ./configure
The next step is to select the modules you want to compile and install. Access menu selects, by typing:
sudo make menuselect
Select the “format_mp3” option to tell Asterisk to build the MP3 module:
After that select the “Save and Exit” button and press “Enter” and start compilation process:
sudo make -j2
The compilation process may take some time depending on your system. You can modify the -j
flag according to the number of cores in your processor.
Once completed, install and configuration Asterisk and its modules by following commands:
sudo make install
sudo make samples
sudo make basic-pbx
sudo make config
sudo ldconfig
Step 3 – Create an Asterisk User
Asterisk runs as the root user by deafult. You need to create a new system user and configure Asterisk.
Run the following command to create a new system user named asterisk
:
sudo adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk
Edit the /etc/default/asterisk
file, to set default user to Asterisk:
sudo nano /etc/default/asterisk
Uncomment the following lines:
AST_USER="asterisk" AST_GROUP="asterisk"
Add the asterisk user to the dialout and audio groups:
sudo usermod -a -G dialout,audio asterisk
After that, you need to change the ownership and permissions 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
Step 4 – Starting Asterisk
At this stage, all set ups are completed. Run the commands below to enable and start the Asterisk service:
sudo systemctl enable asterisk
sudo systemctl start asterisk
To verify that Asterisk is running, run the commands below:
sudo asterisk -vvvr
Step 5 – Configure Firewall
If you have an active ufw firewall, open HTTP ports and ports 5060,5061:
If you don’t have a firewall configured on your server, you can check our guide about how to set up 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
Conclusion
You have successfully installed Asterisk on Ubuntu 22.04 system. To know more how to configure and use Asterisk, check the official documentation.
Feel free to leave a comment below if you have any problem or feedback.