Rocket.Chat is an open-source communication hub. Key features include free audio and video conferencing, guest access, screen and file sharing, LiveChat, LDAP Group Sync, two-factor authentication (2FA), E2E encryption, SSO, dozens of OAuth providers, and unlimited users, guests, channels, messages, searches, and files.

In this guide, I will show you how to install Rocket.Chat on Ubuntu 20.04 server

Getting Started

Update your system packages to the latest version.

apt update && apt upgrade -y

Install and Configure MongoDB

Add the GPG key.

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Add the MongoDB official repository.

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Update package list and install MongoDB.

apt update
apt install mongodb-org

Edit MongoDB configuration.

nano /etc/mongod.conf
replication:
replSetName: "replica01"
systemctl enable --now mongod

Login to the MongoDB shell and enable the replica.

mongo
> rs.initiate()

exit

Install build tools, nginx, curl and graphicsmagic

apt install curl nginx graphicsmagick build-essential

Install nodejs

curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt install nodejs

Install Rocket.Chat

Download the latest version of Rocket.Chat from the official website.

curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz

Extract the downloaded file.

tar -xzf /tmp/rocket.chat.tgz -C /tmp

Install Node.js dependencies.

cd /tmp/bundle/programs/server && npm install
mv /tmp/bundle /opt/Rocket.Chat

Configure the Rocket.Chat service

Add the rocketchat user, set the right permissions on the Rocket.Chat folder.

useradd -M rocketchat && usermod -L rocketchat

chown -R rocketchat: /opt/Rocket.Chat

Create a Systemd Service File For Rocket.Chat.

nano /lib/systemd/system/rocketchat.service
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.service mongod.service
[Service]
ExecStart=/usr/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=http://rocket.unihost.com:3000/ PORT=3000
[Install]
WantedBy=multi-user.target

Warning! Don’t forget to change ROOT_URL.

Reload the systemd daemon and start the Rocket.Chat service.

systemctl daemon-reload

systemctl enable --now rocketchat

systemctl status rocketchat

Open a web browser and access the configured Site URL as on the screen below.

Configure Nginx for Rocket.Chat

Create an Nginx virtual host configuration file.

 1. Nginx as a reverse proxy.

nano /etc/nginx/conf.d/rocketchat.conf
upstream myrocketchat {
server 127.0.0.1:3000;
}

server {
listen 80;
server_name rocket.unihost.com;

access_log /var/log/nginx/rocket.unihost.com.access.log;
error_log /var/log/nginx/rocket.unihost.com.error.log;

location / {
proxy_pass http://myrocketchat/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;

proxy_redirect off;
}
}

 2. Nginx as SSL reverse proxy.

nano /etc/nginx/conf.d/rocketchat.conf
upstream backend {
server 127.0.0.1:3000;
}

server {
listen 443 ssl;
server_name rocket.unihost.com;

# You can increase the limit if your need to.
client_max_body_size 200M;

access_log /var/log/nginx/rocket.unihost.com.access.log;
error_log /var/log/nginx/rocket.unihost.com.error.log;

ssl_certificate /etc/nginx/certificate.crt;
ssl_certificate_key /etc/nginx/certificate.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE

location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Nginx-Proxy true;

proxy_redirect off;
}
}

Check Nginx configuration.

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx to apply changes.

systemctl reload nginx

Now you are able to access chat using your domain name URL.

Enter Admin and Organization information.

Enter server info and agree to Terms and Privacy Policy.

After that, you will be redirected to the dashboard.

 
You have successfully installed and configured Rocket.Chat.