Install Mosquitto MQTT Broker on Arch Linux

Install Mosquitto MQTT Broker on Arch Linux

Mosquitto is a lightweight MQTT broker that uses publish/subscribe model. Since it is written in Python it can run on practically any Linux and many other systems. It also comes with command line utilities to publish and subscribe to MQTT clients.


Install Mosquitto

Install Packer on Arch Linuxinstall Yaourt or use another package wrapper.


Add a PGP signature.

gpg --recv-keys 779B22DFB3E717B7

This may take quite a while, so be patient.


Install Mosquitto from AUR with packer.

packer -S mosquitto


If the key is not added an error will occur preventing the installation.

ERROR: One or more PGP signatures could not be verified!
The build failed.


Install Mosquitto Manually

Download the latest archive.



Unpack the archive.

tar xzf mosquitto-1.4.5.tar.gz


Change the current directory to the newly created directory.

cd mosquitto-1.4.5


Build the package.



Install the package.

sudo make install


Remove the leftover installation files.

sudo rm -Rd mosquitto-1.4.5


Remove the package archive.

sudo rm mosquitto-1.4.5.tar.gz


Configure Mosquitto

Create a system account and group.

sudo useradd -r -s /bin/false mosquitto


Copy configuration file from the example directory.

sudo cp /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf


Open the configuration file.

sudo nano /etc/mosquitto/mosquitto.conf

Add /var/run/ to pid_file line. Optionally change the default user, port and possibly other settings by uncommenting the relevant line and entering the relevant values.


Create a systemd script.

sudo nano /etc/systemd/system/mosquitto.service


Copy the script and save.

Description=Mosquitto MQTT Broker daemon

ExecStartPre=/usr/bin/rm -f /var/run/
ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d
ExecReload=/bin/kill -HUP $MAINPID



Run Mosquitto

Start manually.



Start the systemd service.

sudo systemctl start mosquitto


Enable the systemd service to run on boot.

sudo systemctl enable mosquitto


Use Mosquitto

Subscribe to a topic with mosquitto_sub command.

mosquitto_sub -t home/frontgarden/doorbell


Publish a topic to a broker.

mosquitto_pub -h -p 1883 -t home/livingroom/temperature -m test message

If the target broker is on the same system -h option can be omitted as the host defaults to localhost. Similarly the -p can be omitted if the default port is used. The topic is specified with -t option and the message is -m option.


A fix to the mosquitto_sub: error while loading shared libraries: cannot open shared object file: No such file or directory error is outlined below.


Open the dynamic linker configuration file.

sudo nano /etc/

Add /usr/local/lib line before # End of file line line and save the file.


Configure dynamic linker run-time bindings.

sudo /sbin/ldconfig