I have installed mosquitto server and client packages in my ubuntu machine. When I run command "mosquitto" to run the mosquitto server I am getting an error "Error:address already in use". Why am I getting this error? How can I resolve this?
6 Answers
I ran into the same problem, and resolved the situation by killing the process that was running mosquitto. First, locate the mosquitto process id:
ps -ef | grep mosquitto
This should reveal to you any mosquitto related process. Say for example the process id was 12345, then you could kill it with this:
sudo kill 12345
After that the Error:address already in use message was gone and mosquitto was able to run properly again.

- 2,314
- 1
- 23
- 36
-
Thanks, that helped! – Tia Mar 06 '18 at 16:48
The installation on ubuntu automatically starts the broker for you. Try connecting to check it out:
mosquitto_sub -t '$SYS/#' -v
You will need to install the mosquitto-clients
package if you haven't done so already.

- 11,033
- 3
- 49
- 59
-
Or `systemctl disable mosquitto.service; systemctl stop mosquitto.service` if you only want to run it on command via the console. – Carcigenicate Apr 11 '21 at 22:22
I did run this error, because I did open port 1883 and listener 1883 at the same time , so i delete port 1883

- 23
- 4
Just wait for 1 minute and then fire shut down command again. here is what I followed and got it working
step 1: journalctl -u mosquitto
step 2: service mosquitto stop //and not systemctl stop mosquito
Just to check if it successfully close use this
Optional - step 3 : systemctl status mosquitto.service
and finally
step 4: service mosquito start

- 1
- 1

- 165
- 11
The package installer sets up mosquitto as a systemd service and automatically starts it running for you. It also configures mosquitto to start on a reboot, so you never need to start it manually.
But sometimes it can be helpful to run it in a console window, such as to test a new configuration file, or to watch the output to see clients make and break connections and things like that. In order to do this, you need to stop the background service, and you can use systemctl to do this:
$ systemctl stop mosquitto.service
When you're done with your testing and want to start the background service back up:
$ systemctl start mosquitto.service
To check it, use the status
command:
$ systemctl status mosquitto.service
● mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-05-10 10:17:41 EDT; 1 day 6h ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
...
Main PID: 1110 (mosquitto)
Tasks: 1 (limit: 76805)
Memory: 5.3M
CGroup: /system.slice/mosquitto.service
└─1110 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
May 10 10:17:41 carter systemd[1]: Starting Mosquitto MQTT Broker...
May 10 10:17:41 carter systemd[1]: Started Mosquitto MQTT Broker.
That shows you that it is running, when it started, the process (Main) PID, and the configuration file that it is using, among other thing.

- 455
- 3
- 7
I've discovered that if you have :
socket_domain ipv4
before :
listener 1883 yourhostname
in your config, it results in "Address already in use", you just have to invert the order...

- 421
- 6
- 7