Installing mosquitto on Raspberry Pi

Mosquitto is a BSD licensed message broker that implements the MQ Telemetry Transport protocol versions 3.1 and 3.1.1.

Mosquitto is a lightweight broker and it is available in binary form for most used platforms like Windows, Linux and Mac OS X.
Since it has been written in C language, and the code is small enough, you can compile it for your own platform. And more, installing from source could give you some boosts in performance since you can apply your own optimizations directives….




Let’s start installing mosquitto on a brand new raspbian SD Card.

  • Power on your Raspberry Pi and login in a console.
  • Install the development environment (if your raspbian does not have installed it)

$ sudo apt-get update
$ sudo apt-get install build-essential python quilt devscripts python-setuptools python3

  • Install needed libraries

$ sudo apt-get install libssl-dev libwrap0-dev libc-ares-dev

Note, if you don’t install the libc-ares-dev library you will have the following error:
ares.h: No such file or directory In file included from mosquitto.c

  • Download latest version of Mosquitto (take a look at for version 1.3.4:

$ wget

  • extract the tarballed archive

$ tar zxvf mosquitto-1.3.4.tar.gz

  • go to mosquitto directory

cd mosquitto-1.3.4

  • Build from the sources

$ make all

  • Install mosquitto into your system

$ sudo make install

  • configure dynamic linker run-time bindings

$ sudo ldconfig

  • Ok, your mosquitto broker is ready to run

mosquitto -d -c /etc/mosquitto/mosquitto.conf

Take a look to the /etc/mosquitto/mosquitto.conf configuration file to proper configure your broker.
Now you can try mosquitto:

  • Open two terminal windows.
  • In the first terminal run

$ mosquitto_sub -h -t myTopic

  • In the second terminal run

$ mosquitto_sub -h -t myTopic -m "My first message"


$ mosquitto_pub -h -t myTopic -m "My first message"


At this point, on the first terminal you should have received the message “My first message”

Related Posts

8 thoughts on “Installing mosquitto on Raspberry Pi

  1. Hi great article but wanted to point out an error. The following line in the article should be mosquitto_pub not mosquitto_sub:
    mosquitto_sub -h -t myTopic -m “My first message”

  2. Might be better to add the repo from mentioned in this article:

    However, it was missing a couple things to make your example work.
    sudo apt-get install mosquitto python-mosquitto
    sudo apt-get install mosquitto-clients

    Which was mentioned in this article:

    Anyways, thanks for getting me rolling in the right direction!

  3. Hi David,
    if you install from sources, as described in the post, you shouldn’t have to install python-mosquitto and mosquitto-clients.
    I always prefer to install from sources, specially on ARM devices, since I can optimize applications for speed at compile time.

  4. Totally understand.
    For me, I’m more of a fan of keeping packages updated … easily. I’m pretty bad about keeping packages I compile updated.

  5. Pingback: Mosquitto MQTT-Broker installieren | Denk nach, McFly!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.