LinuxTutorialsUbuntu

How To Install Rocket.Chat on Ubuntu 20.04 LTS

Install Rocket.Chat on Ubuntu 20.04

In this tutorial, we will show you how to install Rocket.Chat on Ubuntu 20.04 LTS. For those of you who didn’t know, Rocket.Chat is one of the most popular open-source chat software. A fantastic alternate to both Slack and compensated live chat software. It’s free, is unlimited and it’s a bunch of cool features like Video chat, Screen sharing, Mobile apps, and more.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Rocket.Chat open-source chat software on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Rocket.Chat on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade
sudo apt install nginx gnupg2 git unzip build-essential software-properties-common graphicsmagick

Step 2. Installing Node.js.

Now add the Node.js official repository to your Ubuntu system:

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

Once the repository is added, install the Node.js with the following command:

sudo apt install nodejs

Step 3. Installing the Nginx Web server on the Ubuntu system.

Nginx is available in the default Ubuntu repositories. To install it run the following command:

sudo apt install nginx

Once the installation is completed, run the commands to enable Nginx to automatically startup when your server starts:

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Meanwhile, you need to make sure that your firewall is configured to allow traffic on HTTP (80) and HTTPS (443) ports. Nginx registers itself as a service with UFW :

sudo ufw allow in "Nginx Full"

Step 4. Install MongoDB on Ubuntu 20.04.

By default, the latest version of MongoDB is not available in the Ubuntu 20.04 default repository. So you will need to add the official MongoDB repository to your system:

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -

Next, add the MongoDB repository with the following command:

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

After that, update your system and refresh existing repositories by running the commands below:

sudo apt update
sudo apt install mongodb-org

Once the installation has been completed, start the MongoDB service and enable it to start at reboot with the following command:

sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod

Next, you will need to define a replica set in MongoDB. You can define it with the following command:

nano /etc/mongod.conf

Add the following lines:

replication:
replSetName: "myreplica"

Save and close the file then restart the MongoDB service:

sudo systemctl restart mongod

Step 5. Installing Rocket.Chat on Ubuntu 20.04.

First, create a new user for Rocket.Chat and add it to www-data a group. You can do it using the following command:

useradd -m -U -r -d /opt/rocket rocket --shell /bin/bash
usermod -a -G rocket www-data
chmod 750 /opt/rocket

Then, switch the user to Rocket.Chat and download the latest version of Rocket.Chat form the official page:

su - rocket
curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tgz
tar -xvzf rocket.chat.tgz
mv bundle Rocket.Chat

Next, change the directory to Rocket.Chat server and install all Node.js dependencies using the following command:

cd Rocket.Chat/programs/server
npm install

Step 6. Create a Systemd Service for Rocket.Chat.

Now we create a systemd service file to manage the Rocket.Chat service:

nano /etc/systemd/system/rocketchat.service

Add the following lines:

[Unit]
Description=Rocket.Chat server
After=network.target nss-lookup.target mongod.target

[Service]
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocket
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=http://rocket.yourdomain.com PORT=3000
ExecStart=/usr/bin/node /opt/rocket/Rocket.Chat/main.js

[Install]
WantedBy=multi-user.target

Save and close the file then start the Rocket.Chat service also enables it to start at system reboot with the following command:

sudo systemctl daemon-reload
sudo systemctl start rocketchat
sudo systemctl enable rocketchat

Step 7. Configure Nginx as a Reverse Proxy.

Create a new Nginx server block for Rocket.Chat access through the proxy:

nano /etc/nginx/sites-available/rocketchat.conf

Add the following lines:

upstream myrocketchat {
  server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name chat.mydomain.com;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        proxy_pass http://my-rocketchat/;
        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 then restart the Nginx service to apply the changes:

sudo systemctl restart nginx

Step 8. Setup Let’s Encrypt SSL.

Now we download and setup Let’s Encrypt for SSL certificate:

sudo apt install certbot python3-certbot-nginx

Restart and enable Nginx service:

nginx -t
sudo systemctl restart nginx

Step 9. Accessing Rocket.Chat on the Ubuntu system.

Rocket.Chat will be available on HTTP port 80 by default. Open your favorite browser and navigate to https://chat.mydomain.com and complete the required steps to finish the installation.

Install Rocket.Chat on Ubuntu 20.04

Congratulations! You have successfully installed Rocket.Chat. Thanks for using this tutorial for installing the Rocket.Chat open-source chat software on your Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you to check the official Rocket.Chat website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button