Cybersecurity Updates & Tools

Install Rocket.Chat on Ubuntu 18.04 with Nginx and Let’s Encrypt

Rocket.Chat is a free, open-source team communication platform built with the Meteor framework. It is a self-hosted alternative to Slack with built-in support for channels, direct messaging, file sharing, video conferencing, voice messages, and a REST API. It is a strong choice for companies and communities that want a private chat system with full control over their data and zero per-user licensing costs.

This guide shows you how to install Rocket.Chat on Ubuntu 18.04 and configure Nginx as an SSL reverse proxy.

Prerequisites:

  • Ubuntu 18.04 server with at least 1 GB of RAM
  • A domain name pointing to your server IP (this guide uses chat.example.com)
  • Nginx installed and a Let’s Encrypt SSL certificate for your domain

Install Rocket.Chat on Ubuntu: Node.js, MongoDB, and System User

Install Node.js and build dependencies. Rocket.Chat needs a specific Node.js version along with native build tools and GraphicsMagick for image processing:

bashsudo apt updatesudo apt install nodejs npm build-essential curl software-properties-common graphicsmagick

Use the n version manager to pin Node.js to v8.11.3, which is the version Rocket.Chat recommends:

bashsudo npm install -g inherits nsudo n 8.11.3

Install MongoDB 4.0. Rocket.Chat uses MongoDB as its data store. Add the official MongoDB repository and install it:

bashsudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'sudo apt updatesudo apt install mongodb-orgsudo systemctl start mongod && sudo systemctl enable mongod

Create a dedicated system user. Running Rocket.Chat as a dedicated user limits what the process can access. Create the rocket user and grant Nginx read access to its home directory:

bashsudo useradd -m -U -r -d /opt/rocket rocketsudo usermod -a -G rocket www-datasudo chmod 750 /opt/rocket

Download Rocket.Chat, Install npm Packages, and Create a Systemd Service

Switch to the rocket user, download the latest release, extract it, and rename the directory:

bashsudo su - rocketcurl -L https://github.com/RocketChat/Rocket.Chat/releases -o rocket.chat.tgztar zxf rocket.chat.tgz && mv bundle Rocket.Chat

Move into the server directory and install all required npm packages:

bashcd Rocket.Chat/programs/servernpm install

Type exit to return to your sudo user. Create the systemd unit file at /etc/systemd/system/rocketchat.service. The unit file sets three environment variables: MONGO_URLROOT_URL (set this to your domain), and PORT=3000. It runs the Rocket.Chat Node.js process as the rocket user and starts after both MongoDB and the network are ready.

Reload systemd, start the service, and enable it at boot:

bashsudo systemctl daemon-reloadsudo systemctl start rocketchatsudo systemctl enable rocketchat

Confirm it is running with sudo systemctl status rocketchat and look for Active: active (running).

Configure Nginx as a Reverse Proxy and Complete the Setup Wizard

Create an Nginx server block at /etc/nginx/sites-available/chat.example.com.conf. The configuration needs two server blocks: one that redirects HTTP to HTTPS, and one that listens on port 443, applies your Let’s Encrypt certificate, and proxies requests to http://127.0.0.1:3000. Include the Upgrade and Connection proxy headers — Rocket.Chat requires WebSocket support for real-time messaging and will not work correctly without them.

Enable the site and reload Nginx:

bashsudo ln -s /etc/nginx/sites-available/chat.example.com.conf /etc/nginx/sites-enabled/sudo systemctl reload nginx

Open https://chat.example.com in your browser. The Rocket.Chat Setup Wizard loads automatically and walks you through four steps: creating the admin account, entering your organization details, setting the server information, and choosing whether to use Rocket.Chat’s cloud gateways for push notifications and the Apps marketplace. Complete all four steps and click Go to your workspace to reach the admin dashboard.

Rocket.Chat is now running on your Ubuntu 18.04 server behind an SSL-secured Nginx reverse proxy. Visit the Rocket.Chat documentation to configure channels, integrations, and user roles for your team. Leave a comment below if you run into any issues.