Installing Building Mosquitto - padogrid/padogrid GitHub Wiki

◀️ Mosquitto Overview :link: Clustering MQTT ▶️


Installing Mosquitto

Mosquitto can be installed via a package manager, i.e., brew, apt, apk, dnf, etc.

macOS

brew install mosquitto

Linux (Debian, Ubuntu)

sudo apt install mosquitto

Linux (Alpine)

sudo apk add mosquitto

Linux (RedHat,Oracle Linux, Fedora, CentOS)

sudo dnf install mosquitto

Building Mosquitto

If you are unable to install Mosquitto using a package manager or the latest version you want to install is not available, then you can build it as described in this section.

:pencil2: The section also includes steps for building cJSON and libwebsockets, which may not be available for some Linux variants.

macOS

cd mosquitto-2.0.15
export OPENSSL_ROOT_DIR=/usr/local/opt/openssl
cmake install -DDOCUMENTATION=NO -DWITH_PLUGINS=NO -DWITH_WEBSOCKETS=YES .
make
sudo make install

If thecmake command fails then install the command line tools and repeat.

xcode-select --install

Linux (Debian, Ubuntu)

cd mosquitto-2.0.15
sudo apt install -y g++ libc-ares-dev libssl-dev libcjson-dev libwebsockets-dev make

vi config.mk
# Enable websockets in config.mk:
WITH_WEBSOCKETS:=yes

make
sudo make install

Linux (Alpine)

cd mosquitto-2.0.15
sudo apk add g++ c-ares openssl-dev libwebsockets-dev
sudo apk add make cmake git
git clone https://github.com/DaveGamble/cJSON.git
cd cJSON
mkdir build
cd build
cmake ..
make
sudo make install

sudo vi /etc/ld.so.conf
# Add the following line in /etc/ld.so.conf:
/usr/local/lib64

cd ..
vi config.mk
# Enable websockets in config.mk:
WITH_WEBSOCKETS:=yes

make
sudo make install

Linux (RedHat,Oracle Linux, Fedora, CentOS)

cd mosquitto-2.0.15
sudo dnf install -y cmake gcc-c++ openssl-devel c-ares-devel
git clone https://github.com/DaveGamble/cJSON.git
cd cJSON
mkdir build
cd build
cmake ..
make
sudo make install

sudo vi /etc/ld.so.conf
# Add the following line in /etc/ld.so.conf:
/usr/local/lib64

sudo /sbin/ldconfig
cd ..
git clone https://github.com/warmcat/libwebsockets.git
cd libwebsockets
cmake .
make
sudo make install
cd ..

vi config.mk
# Enable websockets in config.mk:
WITH_WEBSOCKETS:=yes

make
sudo make install

Test:

mosquitto --version

If the above command displays the following error message:

mosquitto: error while loading shared libraries: libwebsockets.so.19: cannot open shared object file: No such file or directory

then set LD_LIBRARY_PATH as follows. Note that your directory path maybe different the one shown below.

export LD_LIBRARY_PATH=/usr/local/lib

◀️ Mosquitto Overview :link: Clustering MQTT ▶️