# How to Install Mosquitto MQTT Server on Ubuntu 24.04

> URL: https://www.atlantic.net/dedicated-server-hosting/how-to-install-mosquitto-mqtt-server-on-ubuntu-24-04/ | Published: 2024-06-23 | Updated: 2025-07-05 | Author: Hitesh Jethva

Mosquitto MQTT is an open-source message broker that implements the MQTT protocol. It is a lightweight, publish-subscribe network protocol designed for low-bandwidth, high-latency networks. It facilitates efficient communication between devices, making it ideal for Internet of Things (IoT) applications and other scenarios requiring reliable message delivery with minimal overhead. Mosquitto supports various security features, such as TLS encryption and authentication, ensuring secure data transmission. Its ability to handle thousands of concurrent connections makes it suitable for large-scale deployments.

In this tutorial, we will walk you through the process of installing the Mosquitto MQTT Server on Ubuntu 24.04.

## Step 1 – Installing Required Packages

First, we need to update our package list and install some essential packages required for the installation process. Open your terminal and run the following command to make sure the packages you need are available – please note, most of these may already be installed by default:

```bash
apt-get update
apt-get install curl gnupg2 wget git apt-transport-https ca-certificates -y
```

## Step 2 – Adding the Mosquitto PPA

Next, we need to add the Mosquitto PPA (Personal Package Archive) to our system. The PPA provides the latest version of Mosquitto. Run the following command:

```bash
add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y
```

This command adds the Mosquitto PPA to your system’s software sources.

## Step 3 – Installing Mosquitto and Mosquitto Clients

Now that the PPA has been added, we can install Mosquitto and its clients. Execute the following command:

```bash
apt install mosquitto mosquitto-clients -y
```

This command installs the Mosquitto server and the Mosquitto client utilities (mosquitto_sub and mosquitto_pub).

To verify that Mosquitto has been installed correctly and is running, use the **systemctl** command to check its status:

```bash
systemctl status mosquitto
```

You should see an output similar to this:

```bash
● mosquitto.service - Mosquitto MQTT Broker
     Loaded: loaded (/usr/lib/systemd/system/mosquitto.service; enabled; preset: enabled)
     Active: active (running) since Mon 2025-05-12 06:23:36 UTC; 9s ago
       Docs: man:mosquitto.conf(5)
             man:mosquitto(8)
    Process: 49200 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49202 ExecStartPre=/bin/chown mosquitto:mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49204 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
    Process: 49206 ExecStartPre=/bin/chown mosquitto:mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
   Main PID: 49208 (mosquitto)
      Tasks: 1 (limit: 4609)
     Memory: 1.0M (peak: 1.5M)
        CPU: 25ms
     CGroup: /system.slice/mosquitto.service
             └─49208 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

May 12 06:23:36 ubuntu systemd[1]: Starting mosquitto.service - Mosquitto MQTT Broker...
May 12 06:23:36 ubuntu systemd[1]: Started mosquitto.service - Mosquitto MQTT Broker.
```

The output indicates that the Mosquitto service is active and running.

## Step 4 – Configuring Mosquitto

By default, Mosquitto is configured to allow anonymous connections. For security reasons, it is recommended to set up a password for your Mosquitto broker.

Run the following command to create a password file and add a user:

```bash
mosquitto_passwd -c /etc/mosquitto/passwd hjethva
```

You will be prompted to enter and confirm a password for the user you just created (**hjethva**).

```bash
Password: 
Reenter password:
```

Set the correct ownership for the password file:

```bash
chown mosquitto:mosquitto /etc/mosquitto/passwd
```

Next, create a configuration file to specify the listener and password file. Open the configuration file with nano:

```bash
nano /etc/mosquitto/conf.d/default.conf
```

Add the following lines:

```bash
listener 1883
password_file /etc/mosquitto/passwd
```

These lines configure Mosquitto to listen on port 1883 and use the specified password file for authentication.

After making these changes, restart the Mosquitto service to apply the new configuration:

```bash
systemctl restart mosquitto
```

## Step 5 – Testing Mosquitto

To ensure everything is working correctly, we will test Mosquitto using the mosquitto_pub and mosquitto_sub commands.

Open a terminal window and subscribe to a topic – remember to change the YOUR_PASSWORD value.

```bash
mosquitto_sub -u hjethva -P YOUR_PASSWORD -v -t "hello/topic"
```

In another terminal window, publish a message on the same topic – – remember to change the YOUR_PASSWORD value.

```bash
mosquitto_pub -u hjethva -P YOUR_PASSWORD -t 'hello/topic' -m 'hello MQTT'
```

You should see the following output in the subscriber terminal:

```bash
hello/topic hello MQTT
```

This confirms that the Mosquitto server is working correctly.

## Conclusion

In this tutorial, we have covered the installation and configuration of the Mosquitto MQTT server on Ubuntu 24.04. We also demonstrated how to secure the server with a password and tested the setup using Mosquitto client tools. Mosquitto is a powerful and lightweight MQTT broker that is widely used in IoT and messaging applications. With this setup, you can now start building your own MQTT-based solutions. You can try deploying Mosquitto MQTT on [**dedicated server hosting**](https://www.atlantic.net/dedicated-server-hosting/) from Atlantic.Net!
