Skip to content

Installing Mosquitto on Raspberry Pi


The more I integrate a Raspberry Pi into my smart home, the more I need a communications solution to be able to talk between my Raspberry Pi and other Home Automation Hubs (SmartThings…I’m talking about you). That is where MQTT comes in, for those that do not know MQTT is a lightweight messaging protocol designed to minimize network bandwidth usage while ensuring reliability, because of this MQTT is perfect for the Internet of Things.

With MQTT you have “Clients” and “Brokers”. In my use case I have a Raspberry Pi that is a Client and Mosquitto which is a Broker. Mosquitto is an open source MQTT Broker and who does not like open source?

Setting up Mosquitto on a Raspberry Pi is simple and is something that I think every Raspberry Pi user should do as I am sure at one point or another you will have a need for MQTT. To get your Raspberry Pi setup with Mosquitto simply follow the steps below.

First what will you need?

To begin the installation process you will need a MicroSD Memory Card, and the ability to format and burn an image to that MicroSD Memory Card. I am sure most of you know how to do these steps already, but I will give my recommendations, for formatting I prefer to use SD Memory Card Formatter for Windows and to burn the image Etcher.

Memory Card Preparation:

  1. Insert MicroSD Memory Card into a computer
  2. Open SD Memory Card Formatter for Windows
  3. In SD Memory Card Formatter for Windows Select the Drive that corresponds to your Memory Card
  4. In SD Memory Card Formatter for Windows Click Format and wait for it to finish
  5. Download the Raspbian disk image from
  6. Open Etcher.
  7. In Etcher Select the previously Downloaded Image
  8. In Etcher Select the Drive that corresponds to your Memory Card
  9. In Etcher Click Flash and wait for Etcher to Finish

Raspberry Pi Setup:

  1. From the Raspbian Desktop launch Terminal
  2. From Terminal you need to update the signing key using the follow commands,

3. Add the Mosquitto Repo to apt-get by running the following commands in Terminal

4. Install Mosquitto by running the following commands in Terminal

  • sudo apt-get update
  • sudo apt-get install mosquitto mosquitto-clients

That’s it Mosquitto is now running on your Raspberry Pi!

Anyone doing anything interesting with Mosquitto or MQTT in general? Let me know in the comments below.


Mike View All

I am passionate about the IoT and connected devices. Using connectivity to automate our lives will empower civilization to achieve greatness.

4 thoughts on “Installing Mosquitto on Raspberry Pi Leave a comment

  1. brand new fresh install of stretch, i ran the first command and it saved key.
    second command did not work. can you please help ? ive tried everything.. nothing seems to work on stretch when trying to get MQTT broker running. 😦 ive spent hours on it…. i cant figure it out..
    pi@raspberrypi:~ $ sudo wget
    –2018-08-12 17:46:20–
    Resolving (…, 2001:ba8:1f1:f271::2
    Connecting to (||:80… connected.
    HTTP request sent, awaiting response… 200 OK
    Length: 3120 (3.0K) [application/octet-stream]
    Saving to: ‘mosquitto-repo.gpg.key’
    mosquitto-repo.gpg. 100%[===================>] 3.05K –.-KB/s in 0s
    2018-08-12 17:46:21 (40.0 MB/s) – ‘mosquitto-repo.gpg.key’ saved [3120/3120]
    pi@raspberrypi:~ $ sudo apt-key add mosquito-repo.gpg.key
    gpg: can’t open ‘mosquito-repo.gpg.key’: No such file or directory
    pi@raspberrypi:~ $


  2. ive used this a few times now, and keep getting caught out by the typos.
    sudo apt-get install mosquito mosquito-clients
    should be
    sudo apt-get install mosquitto mosquitto-clients
    missing a ‘t’ in each mosquit’t’o


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: