Home Linux Rocket.Chat: How To Install The Messaging System on Debian 9

Rocket.Chat: How To Install The Messaging System on Debian 9



What’s Rocket.Chat

Rocket.Chat is a professional, Slack-like messaging system, developed for companies wanting to privately host their own chat service. It is developed in JavaScript using the Meteor full stack framework.

It has many features, like:

    • Help desk chat
    • Video conferences
    • File sharing
    • Link previews
    • Voice messages

We will install Rocket.Chat on a Debian 9 server.

Getting Started

The first thing to do is to satisfy Rocket.Chat dependencies. Execute the following apt command:

# apt install build-essential graphicsmagick

Install MongoDB

Rocket.Chat works with MongoDB as database system. There aren’t already Debian 9 packages for MongoDB, so we will install it from the tarball.

Download the tarball

First, download with curl the MongoDB tarball

$ curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.4.9.tgz
Extract the archive

Extract the previously downloaded archive by executing the following command:

$ tar -zxvf mongodb-linux*.tgz

Rename and move the directory, for example, in /opt:

# mv mongodb-linux-x86_64-debian81-3.4.9/ /opt/mongodb

Update the PATH variable by adding the /opt/mongodb/bin directory. In ~/.bashrc add the following line:

$ export PATH=${PATH}:/opt/mongodb/bin
Create a unit file

Create a systemctl unit file for MongoDB, executing the following command:

# $EDITOR /lib/systemd/system/mongodb.service

In this file, paste the following content:

Description=A document-oriented database

ExecStart=/opt/mongodb/bin/mongod --unixSocketPrefix=${SOCKETPATH} --config ${CONF} $DAEMON_OPTS


Save and exit.

Reload systemd daemon service:

# systemctl daemon-reload
Start MongoDB

At this point, we can start MongoDB and enable it for starting at boot time:

# systemctl start mongodb
# systemctl enable mongodb

Install Node.js and npm

Rocket.Chat requires Node.js (in particular, any version newer than 4.5) and npm. First of all, add the NodeSource repository:

# curl -sL https://deb.nodesource.com/setup_8.x | bash -

Next, execute the following command for installing both Node.js and npm:

# apt-get install nodejs

Check the Node.js version:

# node --version

Next, install n through npm:

# npm install -g n

With n, it’s possible to change Node.js version.

Install Rocket.Chat

If not exists, create the /var/www directory, which will store Rocket.Chat:

# mkdir -p /var/www
# cd /var/www

In that directory, execute the following command for downloading Rocket.Chat:

# wget https://s3.amazonaws.com/download.rocket.chat/build/rocket.chat-0.58.4.tgz -O rocket.chat.tgz

Extract the archive and rename the extracted folder:

# tar xzf rocket.chat.tgz
# mv bundle Rocket.Chat

Next, set environment variables and run the Rocket.Chat server:

# cd Rocket.Chat/programs/server
# npm install
# cd ../..

# export ROOT_URL=http://example.com:3000/
# export MONGO_URL=mongodb://localhost:27017/rocketchat
# export PORT=3000

Those who are using the replica set should set the MONGO_URL variable with this content: mongodb://localhost:27017/rocketchat?replicaSet=001-rs

Rocket.Chat is installed and configured, but it requires configuration behind a web server. In this tutorial we’ll be using NGINX.

Install NGINX

NGINX can be install with apt:

# apt install nginx

Create a new directory that will contain the SSL certificates:

# mkdir -p /etc/nginx/ssl/

In this directory, generate a new key:

# openssl req -new -x509 -days 365 -nodes -out /etc/nginx/ssl/rocketchat.crt -keyout /etc/nginx/ssl/rocketchat.key

Change permissions to the key file:

# chmod 400 rocketchat.key

Create a Virtual Host file:

# $EDITOR /etc/nginx/sites-available/rocketchat

In this file, paste the following content:

# Upstreams
upstream backend {
# Redirect Options
server {
  listen 80;
  server_name chat.mydomain.com;
  # enforce https
  return 301 https://$server_name$request_uri;
# HTTPS Server
server {
    listen 443;
    server_name chat.mydomain.com;
    error_log /var/log/nginx/rocketchat.access.log;
    ssl on;
    ssl_certificate /etc/nginx/ssl/rocketchat.crt;
    ssl_certificate_key /etc/nginx/ssl/rocketchat.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # dont use SSLv3 ref: POODLE
    location / {
        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;

Save and close the file. Activate the configuration with:

# ln -s /etc/nginx/sites-available/rocketchat /etc/nginx/sites-enabled/rocketchat


# nginx -t

If no errors occur, restart the web server:

# systemctl restart nginx

Next, update the environment variables:

# cd /var/www/Rocket.Chat/ 
# export ROOT_URL=https://chat.example.com 
# export MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=001-rs 
# export PORT=3000

Run Rocket.Chat:

# node main.js

The final step is to insert the following URL into a web browser: https://chat.example.com to register a new admin account and finish the graphical configuration.


There you have it! We’ve just explained how to install and configure your Rocket.Chat Server on a Debian 9 server using NGINX. This useful online communication program can help your team work more efficiently and with more collaboration!




Please enter your comment!
Please enter your name here

Exit mobile version