Mosquitto is an open source MQTT message broker. It is developed by the Eclipse Foundation. In this tutorial, I will show you how to install the Mosquitto broker & Mosquitto MQTT client.

0. Installing Mosquitto Broker

0.1 Installing Mosquitto Broker on Ubuntu/Rasbian/Debian

Open your terminal and update the packages:
sudo apt-get update

Once done enter this command to install the Mosquitto Broker:
sudo apt-get install mosquitto
The broker will automatically start on port 1883 if it got installed correctly. The broker runs as a Linux Service.

This command is to install the Mosquitto Client:
sudo apt-get install mosquitto-clients

Mosquitto’s repository is there by default in the Debian package list.
If you get an error during your install saying “Unable to locate package”, please run this command and then run the above commands again:
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa

To check if mosquitto is running type this command on a terminal:
netstat -a

From the screenshot, you can see that the port 1883 is being used. This indicates that mosquitto is running. If port 1883 is not being used type mosquitto in the terminal. This will run mosquitto. To start/stop mosquitto simply type:

sudo service mosquitto start

sudo service mosquitto stop

0.2 Installing Mosquitto Broker on Windows

To install Mosquitto on Windows first go to this link:
Mosquitto Download Page

Download the 32-bit or 64-bit installer. Install the program.

This will install the broker as a program but not as a Windows service. If you want the broker to run on startup, then you will need to run mosquitto as a service.

In order to do this, first you must run the following on command prompt or powershell opened as “Administrator”:
c:\program files\mosquitto\ ./mosquitto install

(Assuming C:\prgoram files\mosquitto\ is your install location)

This will create a service for mosquitto. To verify if mosquitto is running open command prompt or powershell and type:
netstat -a

You should see mosquitto running on port 1883.

0.3 Installing Mosquitto Broker on macOS

As I don’t have a mac system, I cannot test any method of installing mosquitto on macOS. My friend tried this method and it worked for him:
https://gist.github.com/KazChe/6bcafbaf29e10a7f309d3ca2e2a0f706

If any of the above methods do not work please let me know in the comments below.

Also See:

5 Best MQTT Tools For Testing