install asterisk on raspberry pi

How to Install Asterisk on a Raspberry Pi?

Asterisk is a free and open source PBX to manage your calls automatically (perfect for a small business). In this tutorial, I’ll show you how to install it on Raspberry Pi.

Asterisk is available from the package manager on Raspberry Pi OS, but the latest version can be installed by compiling from the source code provided by Asterisk.org.

The official website gives you the full documentation for everything, but in this post, I’ll give you a short guide tailored for your Raspberry Pi. Let’s get started.

If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.

Want the best experience? Become a premium member for ad-free browsing, access exclusive content, and ask questions in our private forums. Your membership helps support the site!

Prerequisites

  • Raspberry Pi: if possible, a Raspberry Pi 4 or Pi 5. The compilation takes a long time on an older model, and more power can be useful depending on what you’ll do with it.
  • Raspberry Pi OS: if you don’t have it installed yet. The Lite version is fine, as there is no graphical interface for Asterisk. (download here).
  • SD card: Asterisk doesn’t require much space. Here’s my favorite SD card currently.

Installing Asterisk

asterisk logo

Here’s an overview of the steps to install Asterisk on a Raspberry Pi:

  • Install and update Raspberry Pi OS.
  • Download Asterisk from the official GitHub.
  • Compile the source code and install Asterisk.
  • Configure Asterisk using the default configuration files.

I’ll explain each step in the sections below.

Raspberry Pi OS Installation

If you’re using a new SD card for Asterisk, you firstly need to install Raspberry Pi OS on it. As I mentioned, the Lite version is perfect. If you need a step-by-step tutorial on how to do this, you can check this one out..

Once done, don’t forget to enable SSH and update your system before going further:
sudo apt update
sudo apt upgrade

As I will give you many commands to install and configure Asterisk, it’s better to copy and paste them from your computer directly.

Download Asterisk

Note: Asterisk is available in the Raspberry Pi OS repository (sudo apt install asterisk), but it’s an older version. It’s OK for a quick try, but I recommend using the latest version in production.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

All Asterisk downloads are available on this page.

You’ll have to scroll down to get to what we want. The first link is for FreePBX, a GUI interface to manage Asterisk, but it doesn’t support the Pi. Next is a sponsored offer for PBXact Cloud, which isn’t what we’re looking for either.

Finally, you’ll scroll down to the “Source Code” section, which is what you’ll want.

I’ll be showing you how to download the latest version using git. This way, you’ll always get the latest version. Here’s how:

  • Install git:
    sudo apt install git
  • Change to the /usr/local/src directory, where we’ll build it:
    cd /usr/local/src
  • Download the git repository files:
    sudo git clone https://github.com/asterisk/asterisk

If you were wondering about the instructions involving DAHDI and LIBPRI, you won’t need them. DAHDI manages interface cards (and includes many drivers) that you’re probably not using on a Pi. LIBPRI is also not required, as it’s for ISDN interfaces.

Since most of us will be using Asterisk as an IPBX with SIP and Internet, we won’t install these extra packages.

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips.

Install Asterisk

If you’d prefer to follow along as you install, watch our video below:

As for most software built from source, the first step is to check that you have all the requirements for Asterisk installed:

  • Go to the asterisk folder:
    cd /usr/local/src/asterisk
  • Install the prerequisites:
    sudo apt install libedit-dev sqlite3 libsqlite3-dev libjansson-dev libxml2-dev uuid-dev
  • Run the configure script to check that you have all the requirements installed:
    sudo ./configure
    If there is any error, there is probably a package missing on your system.
    Use “apt search” to find the corresponding package and install it (feel free to leave a comment in the community if you find a package missing from my previous command).
  • Then, choose the features you want to use:
    sudo make menuselect

    A menu like this should appear:

    Verify in each submenu that everything you need is checked.
    Press SPACE to select/unselect options you want. Some options are unavailable if the corresponding package is not installed.

    If you don’t really know what you need yet, you can leave it as the default configuration.
    Once you’re done, Press ESC and S to save and exit.
  • You can now run make to compile Asterisk:
    sudo make
    It may take more or less time depending on your Raspberry Pi model and the features you chose (about 15-20 minutes on a Pi 4 with the default configuration).
  • Finally, install all files:
    sudo make install

That’s it, then you have a few commands that are not mandatory but recommended if you are new on Asterisk:

  • Install sample files:
    sudo make samples
    The goal here is to start with a default configuration.
    It will create all the files in the Asterisk folder for you (with many comments in it), so you don’t start from scratch.
  • Install initialization scripts:
    sudo make config
    I recommend doing this, as it will add an initscript, to automatically start Asterisk on boot.
    It’s also useful to start or stop the server if needed.
  • Enable log rotation:
    sudo make install-logrotate
    As we are on Raspberry Pi (so small disk space in general), it’s probably a good idea to do this.
    It will install a script that manages the log files.

The installation is done, and you can continue with the configuration part.

Asterisk Service

Just in case you need it (probably), here are the commands you can use if you installed the initialization script:

  • Start Asterisk:
    sudo /etc/init.d/asterisk start
  • Stop Asterisk:
    sudo /etc/init.d/asterisk stop
  • Check the status:
    sudo /etc/init.d/asterisk status

I recommend checking the status before going further (and start the service if needed).
If it doesn’t work at this point with the default configuration, it’ll probably not work after your changes 🙂

If you don’t have the initialization script, you can start asterisk with:
sudo asterisk -gcv

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Asterisk stops when you close your window or SSH connection (you can use a screen to keep it running in background).

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Configuring Asterisk

Now that you’ve installed Asterisk, it’s time to configure the program to fit your needs.

Files Location

The configuration files for Asterisk are located in /etc/asterisk. There are many files here (119 in my test), so it’s difficult to explain in a few lines, but I’ll cover the more important ones later.

Just a quick note here: if you want to use or upload sounds in your configuration, they are located under /var/lib/asterisk/sounds. By default, you’ll get only sounds in English, but many languages are available in menuselect if you need another one.

Main Configuration Files

As I’ve mentioned, you don’t need all the configuration files. Here are the more important ones and what they do:

  • sip.conf: In this file, you need to configure your SIP accounts. SIP is a protocol to manage calls over the Internet. You need to find a provider (some are available for free like LinPhone), and check with them on how to configure their service for Asterisk.
  • users.conf: Each user (=phone or softphone) also needs to be configured. If you use a softphone on your computer, you need to define the SIP account in this file (number and password at least). Check the file sample for an example.
    Asterisk is compatible with any SIP phone. I have used a lot of this brand in the past with great results if you are looking for one.
  • extensions.conf: This file is like Asterisk’s brain. Editing this file lets you manage what should happen when you receive or make a call. You can have a simple configuration that just makes your phone ring when someone calls.
    Or you can do something more complicated, with opening hours, a welcome message, or ring several phones. It’s probably the most complicated file to understand when you’re start out.

Basically, you don’t need to edit the other files if all you want is a basic configuration.

Going Further

I will not explain in detail all the configurations possible here. But you’ll find some more information on these sites:

And you’ll also find help on other websites and forums because Asterisk is a well-known product with lots of users all over the world.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Conclusion

That’s it! You now know how to install Asterisk on a Raspberry Pi. It seems to work correctly on a Pi 4, so it could be great for use at home or in a small business.

I’ve been using Asterisk at work for years, with 70 people answering calls for our customer service. The load average stays very low, even with that number of simultaneous calls. Once you overcome the learning curve, it’s powerful and not so complicated.

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

How would you rate this article?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Spread the word!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Similar Posts

8 Comments

  1. OK, I guess this software is supposed to answer phone calls but how?
    What hardware is needed? That should have been part of your article for those of us who never heard of Asterisk before.

    1. Hi,

      As explained in the tutorial, the goal was to try installing Asterisk on a Raspberry, not to explain the whole thing.
      But to give you an idea, you don’t need any hardware.
      You need two things once installed:
      – a SIP provider
      – a softphone to answer calls on your PC or smartphone (3CX, Zoiper, …). You can also use an IP phone if you prefer (examples on Amazon: https://amzn.to/3f7NmKI)

  2. Hi Patrick
    Thank for the article.
    My main use for a RasPBX would be to take messages and record calls automatically on my home POTS.
    I have a USR5367 voice modem intended for this purpose.
    Is this project doable, and if so can you offer advice?

  3. Hi!, sorry Sr. but can i ask you what the specs of your server when you say that your system was supporting that 70 people on calls ? , just for me to take an example of the hardware needed.

    1. Hi,
      It’s a small virtual machine.
      2vCPU/2Go RAM, load average near 0 almost all the time, doesn’t require so much.

  4. Congratulations. beautiful article.
    When I run this “sudo /etc/init.d/asterisk start” command I get this “ERROR: /usr/sbin/asterisk not found” error message

    1. Try “sudo service asterisk start” maybe.
      If it doesn’t work, make sure you have done all the commands after the installation.

Comments are closed.