A Guide to Install RabbitMQ on Ubuntu 24.04

By Raman Kumar

Updated on Sep 16, 2024

In this tutorial, we'll guide you to install RabbitMQ on Ubuntu 24.04 server.

RabbitMQ is an open-source message broker widely used for handling messaging between distributed systems. It supports multiple messaging protocols, including the Advanced Message Queuing Protocol (AMQP), making it a powerful tool for managing communication between microservices, event-driven architectures, and other distributed applications. RabbitMQ allows asynchronous message passing, enabling systems to decouple services and scale efficiently.

It offers features such as message routing, message acknowledgment, persistence, and high availability, making it suitable for both small projects and large enterprise applications. Its built-in management interface allows for easy monitoring, configuration, and management of queues and exchanges.

Prerequisites

  • An Ubuntu 24.04 dedicated server or KVM VPS with root or sudo privileges.
  • A basic understanding of the command line.

Install RabbitMQ on Ubuntu

Step 1: Update the System

Before installing any software, it's a good idea to update your system's package list to ensure that you are working with the latest versions of system packages:

sudo apt update
sudo apt upgrade -y

Step 2: Install RabbitMQ and Erlang

Following commands are copied from RabbitMQ official documentation. We are using Apt with Cloudsmith Mirrors.

Install Essential Dependencies

sudo apt-get install curl gnupg apt-transport-https -y

Add Repository Signing Keys

## Team RabbitMQ's main signing key
curl -1sLf "https://keys.openpgp.org/vks/v1/by-fingerprint/0A9AF2115F4687BD29803A206B73A36E6026DFCA" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/com.rabbitmq.team.gpg > /dev/null

## Community mirror of Cloudsmith: modern Erlang repository
curl -1sLf https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg > /dev/null

## Community mirror of Cloudsmith: RabbitMQ repository
curl -1sLf https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/rabbitmq.9F4587F226208342.gpg > /dev/null

Add a Repository (Apt Source List) File

As with all 3rd party apt repositories, a file describing the RabbitMQ and Erlang package repositories must be placed under the /etc/apt/sources.list.d/ directory. /etc/apt/sources.list.d/rabbitmq.list is the recommended location.

sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
## Provides modern Erlang/OTP releases from a Cloudsmith mirror
##
deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/ubuntu noble main
deb-src [signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/ubuntu noble main

# another mirror for redundancy
deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/ubuntu noble main
deb-src [signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/ubuntu noble main

## Provides RabbitMQ from a Cloudsmith mirror
##
deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-server/deb/ubuntu noble main
deb-src [signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-server/deb/ubuntu noble main

# another mirror for redundancy
deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-server/deb/ubuntu noble main
deb-src [signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-server/deb/ubuntu noble main
EOF

After updating the list of apt sources it is necessary to run apt-get update:

sudo apt-get update -y

RabbitMQ is built on the Erlang programming language, so Erlang must be installed before RabbitMQ. To install Erlang, you will first need to add the Erlang repository to your system.

## Install Erlang packages
sudo apt-get install -y erlang-base \
                        erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
                        erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
                        erlang-runtime-tools erlang-snmp erlang-ssl \
                        erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl

Verify the installation

erl -version

Output: 

Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 14.2.5.2

Install RabbitMQ

## Install rabbitmq-server and its dependencies
sudo apt-get install rabbitmq-server -y --fix-missing

Step 3: Manage RabbitMQ Service

Once RabbitMQ is installed, it will be enabled and started automatically. You can check the status of the RabbitMQ service using the following command:

sudo systemctl status rabbitmq-server

To start, stop, or restart the RabbitMQ service, use these commands:

Start RabbitMQ:

sudo systemctl start rabbitmq-server

Stop RabbitMQ:

sudo systemctl stop rabbitmq-server

Restart RabbitMQ:

sudo systemctl restart rabbitmq-server

Enable RabbitMQ to start automatically on boot:

sudo systemctl enable rabbitmq-server

Step 4: Enable RabbitMQ Management Plugin

RabbitMQ includes a web-based management interface that makes it easier to manage and monitor RabbitMQ. To enable this plugin, run the following command:

sudo rabbitmq-plugins enable rabbitmq_management

After enabling the plugin, the management interface will be accessible at http://<your-server-ip>:15672/. To check your server’s IP address, you can use:

hostname -I

By default, RabbitMQ creates a guest user with credentials guest/guest. However, the guest user can only connect from localhost.

Step 5: Create a New RabbitMQ User

For security reasons, it's better to create a new admin user and disable the guest account for remote access.

Create a new RabbitMQ user. Replace your_user with your username and your_password with your desired password:

sudo rabbitmqctl add_user your_user your_password

Grant administrator privileges to the new user:

sudo rabbitmqctl set_user_tags your_user administrator

Set permissions for the new user:

sudo rabbitmqctl set_permissions -p / your_user ".*" ".*" ".*"

Remove the default guest user if not needed:

sudo rabbitmqctl delete_user guest

Step 6: Adjust Firewall Settings

If you have UFW (Uncomplicated Firewall) enabled, you'll need to allow RabbitMQ ports through the firewall to access the management interface and the message broker. RabbitMQ uses the following default ports:

  • 5672 for messaging.
  • 15672 for the management plugin.

To open these ports, run:

sudo ufw allow 5672
sudo ufw allow 15672

Check the firewall status to confirm:

sudo ufw status

Step 7: Access RabbitMQ Management Interface

Now, you can access the RabbitMQ management interface by opening your browser and going to:

http://<your-server-ip>:15672/

RabbitMQ login page

Log in using the new user credentials you created.

Step 8: Testing RabbitMQ

To test that RabbitMQ is running and communicating correctly, you can use the following command to list RabbitMQ queues:

sudo rabbitmqctl list_queues

If you see an empty list, it means RabbitMQ is working, but no queues have been created yet.

Conclusion

You have successfully seen a guide to install RabbitMQ on Ubuntu 24.04 server. You can now use RabbitMQ to build asynchronous messaging in your applications, and with the web management interface, you can easily monitor and manage the RabbitMQ server.