How to install Asterisk 16 LTS on Ubuntu 21.04

To Install Asterisk 16 LTS on Ubuntu 21.04

Introduction:

Asterisk is a complete telephony server that provides Private Branch Exchange (PBX), Interactive Voice Response (IVR), Automated Call Distribution (ACD), Voice over IP (VoIP) gatewaying, Conferencing, and a wide variety of other telephony applications to a broad range of telephony devices including packet voice devices.

Installation Procedure:

Step 1:Check the OS version by using following command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2:Change the directory by using the below command

root@linuxhelp:~# cd /usr/src/

Step 3:Download the Asterisk by using below command

root@linuxhelp:/usr/src# curl -O http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 26.6M  100 26.6M    0     0  7375k      0  0:00:03  0:00:03 --:--:-- 7373k

Step 4:Extract the downloaded file by using the below command

root@linuxhelp:/usr/src# tar xvf asterisk-16-current.tar.gz
asterisk-16.23.0/
asterisk-16.23.0/.cleancount
asterisk-16.23.0/.gitignore
asterisk-16.23.0/.gitreview
asterisk-16.23.0/.lastclean
asterisk-16.23.0/.version
asterisk-16.23.0/BSDmakefile
asterisk-16.23.0/BUGS
asterisk-16.23.0/CHANGES
asterisk-16.23.0/COPYING
asterisk-16.23.0/CREDITS
asterisk-16.23.0/ChangeLog
asterisk-16.23.0/LICENSE
asterisk-16.23.0/Makefile
asterisk-16.23.0/Makefile.moddir_rules
asterisk-16.23.0/Makefile.rules
asterisk-16.23.0/README-SERIOUSLY.bestpractices.md
asterisk-16.23.0/README-addons.txt
asterisk-16.23.0/README.md
asterisk-16.23.0/UPGRADE.txt
asterisk-16.23.0/Zaptel-to-DAHDI.txt
asterisk-16.23.0/addons/
asterisk-16.23.0/addons/.gitignore
asterisk-16.23.0/addons/Makefile
asterisk-16.23.0/utils/expr2.testinput
asterisk-16.23.0/utils/extconf.c
asterisk-16.23.0/utils/frame.c
asterisk-16.23.0/utils/frame.h
asterisk-16.23.0/utils/muted.c
asterisk-16.23.0/utils/smsq.c
asterisk-16.23.0/utils/stereorize.c
asterisk-16.23.0/utils/streamplayer.c
asterisk-16.23.0/utils/utils.xml

Step 5:Change the directory to the “asterisk-16.23.0” by using the below command

root@linuxhelp:/usr/src# cd asterisk-16.23.0/

Step 6: Download the mp3 decoder library into the source tree by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# contrib/scripts/get_mp3_source.sh
A    addons/mp3
A    addons/mp3/dct64_i386.c
A    addons/mp3/MPGLIB_TODO
A    addons/mp3/mpg123.h
A    addons/mp3/layer3.c
A    addons/mp3/mpglib.h
A    addons/mp3/decode_ntom.c
A    addons/mp3/interface.c
A    addons/mp3/MPGLIB_README
A    addons/mp3/common.c
A    addons/mp3/huffman.h
A    addons/mp3/tabinit.c
A    addons/mp3/Makefile
A    addons/mp3/README
A    addons/mp3/decode_i386.c
Exported revision 202.

Step 7:Update the apt source list by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# apt update 
Hit:1 http://in.archive.ubuntu.com/ubuntu hirsute InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu hirsute-updates InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu hirsute-backports InRelease      
Hit:4 http://security.ubuntu.com/ubuntu hirsute-security InRelease         
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

Step 8:Install the dependencies by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# contrib/scripts/install_prereq install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm11
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  aptitude-common libboost-iostreams1.74.0 libcwidget4 libxapian30
Suggested packages:
  apt-xapian-index aptitude-doc-en | aptitude-doc debtags tasksel libcwidget-dev xapian-tools
The following NEW packages will be installed:
  aptitude aptitude-common libboost-iostreams1.74.0 libcwidget4 libxapian30
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,027 kB of archives.
After this operation, 19.7 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu hirsute/universe amd64 aptitude-common all 0.8.13-
.
(Reading database ... 177765 files and directories currently installed.)
Setting up unixodbc-dev:amd64 (2.3.6-0.1build1) ...
Processing triggers for libglib2.0-0:amd64 (2.68.1-1~ubuntu21.04.1) ...
Processing triggers for libc-bin (2.33-0ubuntu5) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for sgml-base (1.30) ...
Processing triggers for install-info (6.7.0.dfsg.2-6) ...
Setting up libgmime-3.0-dev:amd64 (3.2.7-1) ...
Setting up libpcap0.8-dev:amd64 (1.10.0-2) ...
Setting up libsrtp2-dev (2.3.0-5) ...
                                         
#############################################
 ## install completed successfully
#############################################

Step 9:Run the configure script to build the dependencies by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# ./configure 
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
 [pjproject]  Configuring with --prefix=/opt/pjproject --disable-speex-codec --disable-speex-aec --disable-bcg729 --disable-gsm-codec --disable-ilbc-codec --disable-l16-codec --disable-g722-codec --disable-g7221-codec --disable-opencore-amr --disable-silk --disable-opus --disable-video --disable-v4l2 --disable-sound --disable-ext-sound --disable-sdl --disable-libyuv --disable-ffmpeg --disable-openh264 --disable-ipp --disable-libwebrtc --without-external-pa --without-external-srtp --disable-resample --disable-g711-codec --enable-epoll
config.status: creating autoconfig.h
configure: Menuselect build configuration successfully completed

               .$$$$$$$$$$$$$$$=..      
            .$7$7..          .7$$7:.    
          .$$:.                 ,$7.7   
        .$7.     7$$$$           .$$77  
     ..$$.       $$$$$            .$$$7 
    ..7$   .?.   $$$$$   .?.       7$$$.
   $.$.   .$$$7. $$$$7 .7$$$.      .$$$.
 .777.   .$$$$$$77$$$77$$$$$7.      $$$,
 $$$~      .7$$$$$$$$$$$$$7.       .$$$.
.$$7          .7$$$$$$$7:          ?$$$.
$$$          ?7$$$$$$$$$$I        .$$$7 
$$$       .7$$$$$$$$$$$$$$$$      :$$$. 
$$$       $$$$$$7$$$$$$$$$$$$    .$$$.  
$$$        $$$   7$$$7  .$$$    .$$$.   
$$$$             $$$$7         .$$$.    
7$$$7            7$$$$        7$$$      
 $$$$$                        $$$       
  $$$$7.                       $$  (TM)     
   $$$$$$$.           .7$$$$$$  $$      
     $$$$$$$$$$$$7$$$$$$$$$.$$$$$$      
       $$$$$$$$$$$$$$$$.                

configure: Package configured for: 
configure: OS type  : linux-gnu
configure: Host CPU : x86_64
configure: build-cpu:vendor:os: x86_64 : pc : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : pc : linux-gnu :

Step 10:Setup the Menu option by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# make menuselect
CC="cc" CXX="g++" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" cmenuselect
make[1]: Entering directory '/usr/src/asterisk-16.23.0/menuselect'
gcc -g -D_GNU_SOURCE -Wall -Wno-deprecated-declarations -DHAVE_NCURSES -I/usr/include/libxml2   -c -o menuselect.o menuselect.c
gcc -g -D_GNU_SOURCE -Wall -Wno-deprecated-declarations -DHAVE_NCURSES   -c -o strcompat.o strcompat.c
gcc -g -D_GNU_SOURCE -Wall -Wno-deprecated-declarations -DHAVE_NCURSES     -c -o menuselect_curses.o menuselect_curses.c
gcc  -o cmenuselect menuselect.o strcompat.o menuselect_curses.o -lncurses  -ltinfo  -lxml2
make[1]: Leaving directory '/usr/src/asterisk-16.23.0/menuselect'
CC="cc" CXX="g++" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" nmenuselect
make[1]: Entering directory '/usr/src/asterisk-16.23.0/menuselect'
gcc -g -D_GNU_SOURCE -Wall -Wno-deprecated-declarations -DHAVE_NCURSES    -c -o menuselect_newt.o menuselect_newt.c
gcc  -o nmenuselect menuselect.o strcompat.o menuselect_newt.o -lnewt  -lxml2
make[1]: Leaving directory '/usr/src/asterisk-16.23.0/menuselect'
CC="cc" CXX="g++" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" gmenuselect
make[1]: Entering directory '/usr/src/asterisk-16.23.0/menuselect'
make[1]: Nothing to be done for 'gmenuselect'.
make[1]: Leaving directory '/usr/src/asterisk-16.23.0/menuselect'
make[1]: Entering directory '/usr/src/asterisk-16.23.0'

Step 11:Mark the chan_ooh and format_mp3 on ADD-ons

Step 12:Select the Audio format packages on core sound packages

Step 13:Select the Minimal Modules on Music on Hold

Step 14:Select the following packages on Extra sound packages

Step 15:Select the app_macro on Applications

Step 16:Build Asterisk by running make

root@linuxhelp:/usr/src/asterisk-16.23.0# 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 -> hash/hash_buf.o
   [CC] hash/hash_func.c -> hash/hash_func.o
   [CC] hash/hash_log2.c -> hash/hash_log2.o
   [CC] hash/hash_page.c -> hash/hash_page.o
   [CC] hash/ndbm.c -> hash/ndbm.o
   [CC] btree/bt_search.c -> btree/bt_search.o
   [CC] btree/bt_seq.c -> btree/bt_seq.o
   [LD] format_mp3.o mp3/common.o mp3/dct64_i386.o mp3/decode_ntom.o mp3/layer3.o mp3/tabinit.o mp3/interface.o -> format_mp3.so
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               +
 +-------------------------------------------+

Step 17:After build run make to install Asterisk

root@linuxhelp:/usr/src/asterisk-16.23.0# make install
Installing modules from channels...
Installing modules from pbx...
Installing modules from apps...
Installing modules from codecs...
Installing modules from formats...
Installing modules from cdr...
Installing modules from cel...
Installing modules from bridges...
Installing modules from funcs...
Installing modules from tests...
Installing modules from main...
Installing modules from res...
Installing modules from addons...
/usr/bin/install -c -d "/usr/include/asterisk/doxygen"
/usr/bin/install -c -m 644 include/asterisk.h "/usr/include"
/usr/bin/install -c -m 644 include/asterisk/*.h "/usr/include/asterisk"
/usr/bin/install -c -m 644 include/asterisk/doxygen/*.h "/usr/include/asterisk/doxygen"
if [ -n "" ]; then \
	for h in ; do rm -f "/usr/include/asterisk/$h"; done \
fi
/usr/bin/install -c -m 755 contrib/scripts/astversion "/usr/sbin/"
/usr/bin/install -c -m 755 contrib/scripts/astgenkey "/usr/sbin/"
/usr/bin/install -c -m 755 contrib/scripts/autosupport "/usr/sbin/"
if [ ! -f /sbin/launchd ]; then \
	./build_tools/install_subst contrib/scripts/safe_asterisk "/usr/sbin/safe_asterisk"; \
fi
/usr/bin/install -c -m 644 doc/core-*.xml "/var/lib/asterisk/documentation"
/usr/bin/install -c -m 644 doc/appdocsxml.xslt "/var/lib/asterisk/documentation"
/usr/bin/install -c -m 644 doc/appdocsxml.dtd "/var/lib/asterisk/documentation"
/usr/bin/install -c -m 644 doc/asterisk.8 "/usr/share/man/man8"
/usr/bin/install -c -m 644 doc/astdb*.8 "/usr/share/man/man8"
/usr/bin/install -c -m 644 contrib/scripts/astgenkey.8 "/usr/share/man/man8"
/usr/bin/install -c -m 644 contrib/scripts/autosupport.8 "/usr/share/man/man8"
/usr/bin/install -c -m 644 contrib/scripts/safe_asterisk.8 "/usr/share/man/man8"
if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
	/usr/bin/install -c -m 644 contrib/firmware/iax/iaxy.bin "/var/lib/asterisk/firmware/iax/iaxy.bin"; \
fi
CFLAGS="  -I/usr/include/libxml2 -pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations   -g3 " build_tools/mkpkgconfig "/usr/lib/pkgconfig";
find static-http | while read x; do \
	if test -d $x; then \
		/usr/bin/install -c -m 755 -d "/var/lib/asterisk/$x"; \
	else \
		/usr/bin/install -c -m 644 $x "/var/lib/asterisk/$x" ; \
	fi \
done
/usr/bin/install -c -m 644 doc/core-en_US.xml "/var/lib/asterisk/static-http";
/usr/bin/install -c -m 644 doc/appdocsxml.xslt "/var/lib/asterisk/static-http";
if [ -d doc/tex/asterisk ] ; then \
	/usr/bin/install -c -d "/var/lib/asterisk/static-http/docs" ; \
	for n in doc/tex/asterisk/* ; do \
		/usr/bin/install -c -m 644 $n "/var/lib/asterisk/static-http/docs" ; \
	done \
fi
for x in images/*.jpg; do \
	/usr/bin/install -c -m 644 $x "/var/lib/asterisk/images" ; \
done
make -C sounds install
make[1]: Entering directory '/usr/src/asterisk-16.23.0/sounds'


HTTP request sent, awaiting response... 200 OK
Length: 1777967 (1.7M) [application/x-gzip]
Saving to: ‘asterisk-moh-opsound-gsm-2.03.tar.gz’

asterisk-moh-opsound-gsm-2.03 100%[===============================================>]   1.70M  10.7MB/s    in 0.2s    

2022-01-19 04:30:57 (10.7 MB/s) - ‘asterisk-moh-opsound-gsm-2.03.tar.gz’ saved [1777967/1777967]

make[1]: Leaving directory '/usr/src/asterisk-16.23.0/sounds'
find rest-api -name "*.json" | while read x; do \
	/usr/bin/install -c -m 644 $x "/var/lib/asterisk/rest-api" ; \
done
 +---- 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    +
 +-------------------------------------------+

Step 18:Install the samples by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# make samples
Installing adsi config files...
/usr/bin/install -c -d "/etc/asterisk"
Installing configs/samples/asterisk.adsi
Installing configs/samples/telcordia-1.adsi
Installing other config files...
Installing file configs/samples/acl.conf.sample
Installing file configs/samples/adsi.conf.sample
Installing file configs/samples/agents.conf.sample
Installing file configs/samples/alarmreceiver.conf.sample
Installing file configs/samples/alsa.conf.sample
Installing file configs/samples/amd.conf.sample
Installing file configs/samples/app_mysql.conf.sample
Installing file configs/samples/app_skel.conf.sample
Installing file configs/samples/ari.conf.sample
Installing file configs/samples/ast_debug_tools.conf.sample
Installing file configs/samples/asterisk.conf.sample
Installing file configs/samples/calendar.conf.sample
Installing file configs/samples/ccss.conf.sample
Installing file configs/samples/indications.conf.sample
Installing file configs/samples/logger.conf.sample
Installing file configs/samples/manager.conf.sample
Installing file configs/samples/vpb.conf.sample
Installing file configs/samples/xmpp.conf.sample
Updating asterisk.conf
/usr/bin/install -c -d "/var/spool/asterisk/voicemail/default/1234/INBOX"
build_tools/make_sample_voicemail "//var/lib/asterisk" "//var/spool/asterisk"
Installing file phoneprov/000000000000.cfg
Installing file phoneprov/000000000000-directory.xml
Installing file phoneprov/000000000000-phone.cfg
Installing file phoneprov/polycom_line.xml
Installing file phoneprov/polycom.xml
Installing file phoneprov/snom-mac.xml

Step 19:Install the configs by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# make config

Step 20: ldconfig creates the necessary links and cache to the most recent shared libraries found

root@linuxhelp:/usr/src/asterisk-16.23.0# ldconfig

Step 21:Create a group as asterisk by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# groupadd asterisk

Step 22:Create a user as asterisk and adding to the group asterisk by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# useradd -r -d /var/lib/asterisk -g asterisk asterisk

Step 23:Add asterisk user to the some more groups by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# usermod -aG audio,dialout asterisk

Step 24:Change the ownership as asterisk for the following directories

root@linuxhelp:/usr/src/asterisk-16.23.0# chown -R asterisk.asterisk /etc/asterisk
root@linuxhelp:/usr/src/asterisk-16.23.0# chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
root@linuxhelp:/usr/src/asterisk-16.23.0# chown -R asterisk.asterisk /usr/lib/asterisk

Step 25:Set default user as asterisk by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# vim /etc/default/asterisk 

Step 26:Set the Asterisk conf will run as asterisk user by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# vim /etc/asterisk/asterisk.conf

Step 27:Restart the Asterisk service by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# systemctl restart asterisk

Step 28:Enable the Asterisk service to start on boot by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# systemctl enable asterisk 
asterisk.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable asterisk

Step 29:Check the status of the Asterisk service by using the below command

root@linuxhelp:/usr/src/asterisk-16.23.0# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Wed 2022-01-19 04:44:40 IST; 29s ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 77 (limit: 2254)
     Memory: 114.7M
     CGroup: /system.slice/asterisk.service
             └─50939 /usr/sbin/asterisk -U asterisk -G asterisk

Jan 19 04:44:39 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Jan 19 04:44:39 linuxhelp asterisk[50924]:  * Starting Asterisk PBX: asterisk
Jan 19 04:44:40 linuxhelp asterisk[50924]:    ...done.
Jan 19 04:44:40 linuxhelp systemd[1]: Started LSB: Asterisk PBX.
Jan 19 04:44:42 linuxhelp asterisk[50939]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/ra>
Jan 19 04:44:42 linuxhelp asterisk[50939]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/ra>

Step 30: Login to the Asterisk CLI by using the below command

Root@linuxhelp:/usr/src/asterisk-16.23.0# asterisk -rvv
Asterisk 16.23.0, Copyright (C) 1999 - 2021, Sangoma Technologies Corporation 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.
=========================================================================
Running as user 'asterisk'
Running under group 'asterisk'
Connected to Asterisk 16.23.0 currently running on linuxhelp (pid = 50939)
linuxhelp*CLI> 

By this the installation of Asterisk 16 LTS on Ubuntu 21.04 have been Completed

FAQ
Q
What is RTP in Asterisk?
A
The rtp.conf file controls the Real-time Transport Protocol (RTP) ports that Asterisk uses to generate and receive RTP traffic.
Q
What is the difference between asterisk and FreePBX?
A
FreePBX is a web-based open-source GUI that controls and manages Asterisk.
Q
What is SIP in asterisk?
A
The SIP Channel Module enables Asterisk to communicate via VoIP with SIP telephones and exchanges.
Q
Why do we need the Asterisk framework?
A
The Asterisk framework is for building multi-protocol, real-time communications applications, and solutions
Q
How to log on to the Asterisk CLI?
A
To Logon to the Asterisk CLI use "asterisk -r" command.