install rocket.chat ubuntu 1

Rocket.Chat is an open source self hosted chat platform that can be used as an alternative to Slack. It comes with many features that you would like to have in your self hosted environment e.g. video conferencing, group chats and integration with other platforms.

In this guide we shall discuss how to install Rocket.Chat server on Ubuntu 20.04 LTS with Let’s Encrypt.

We will use the following for the installation:

  • Ubuntu 20.04 LTS server
  • Node.js
  • MongoDB
  • Nginx webserver
  • Let’s Encrypt SSL certificate
  • Domain name – In this example we use chat.hirebestengineers.com

Step 1 – Update Ubuntu system

Update your Ubuntu 20.04 system

sudo apt-get -y update

Step 2 – Install Required package dependencies

Add MongoDB GPG signing key:

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

Add MongoDB repository

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

Configure Node.js to be installed through the Ubuntu package manager:

sudo apt-get -y update && sudo apt-get install -y curl && curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -

Install Node.js, MongoDB, build tools and graphicsmagick:

sudo apt-get install -y build-essential mongodb-org nodejs graphicsmagick

Installing a different version of node than the base version installed causes conflicts with Rocket.Chat in Ubuntu 20.04. You should only install a version that is same as the base version or create a symbolic link to the base version. To check the installed version:

$ node --version
v12.22.2

Install inherits and n.

$ sudo npm install -g inherits n
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
+ [email protected]
+ [email protected]
added 2 packages from 2 contributors in 0.628s

Create a symbolic link for the node binary file to

sudo ln -s /usr/bin/node /usr/local/bin/node

Step 3 – Install Rocket.Chat on Ubuntu 20.04

Download the latest version of Rocket.Chat with the following

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

Extract the downloaded file to /tmp folder

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

Install Rocket.Chat to a directory of your choice. In this guide, we shall install it in /opt directory

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

Step 4 – Create Rocketchat system user

Create a rocketchat user and assign ownership to the Rocket.Chat folder.

sudo useradd -M rocketchat && sudo usermod -L rocketchat
sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat

Once the user has been created then you can proceed to create the service.

Step 5 – Create Rocket.Chat service

Create Rocket.Chat service unit file.

cat << EOF |sudo tee -a /etc/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/local/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target
EOF

Configure the storage engine and replication for MongoDB then start MongoDB service.

sudo sed -i "s/^#replication:/replication:\n  replSetName: rs01/" /etc/mongod.conf

Start and enable MongoDB service

sudo systemctl daemon-reload
sudo systemctl enable mongod && sudo systemctl restart mongod

Confirm MongoDB service:

$ systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-07-12 19:34:41 UTC; 16s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 20623 (mongod)
     Memory: 110.0M
     CGroup: /system.slice/mongod.service
             └─20623 /usr/bin/mongod --config /etc/mongod.conf

Jul 12 19:34:41 ubuntu systemd[1]: Started MongoDB Database Server.

Test:

$ mongo --eval "printjson(rs.initiate())"
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("022d302f-1a1d-468a-83d7-2d5b359d1121") }
MongoDB server version: 4.4.6
{
	"operationTime" : Timestamp(1626118543, 8),
	"ok" : 0,
	"errmsg" : "already initialized",
	"code" : 23,
	"codeName" : "AlreadyInitialized",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1626118543, 8),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}

Start Rocket.Chat service:

sudo systemctl enable rocketchat && sudo systemctl start rocketchat

Check if the service is running:

$ systemctl status rocketchat
● rocketchat.service - The Rocket.Chat server
     Loaded: loaded (/lib/systemd/system/rocketchat.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2020-11-27 10:05:54 UTC; 31s ago
   Main PID: 28294 (node)
      Tasks: 11 (limit: 19076)
     Memory: 559.7M
     CGroup: /system.slice/rocketchat.service
             └─28294 /usr/local/bin/node /opt/Rocket.Chat/main.js

Nov 27 10:06:20 chat rocketchat[28294]: ➔ |      MongoDB Version: 4.0.21                      |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |       MongoDB Engine: mmapv1                      |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |             Platform: linux                       |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |         Process Port: 3000                        |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |             Site URL: http://0.0.0.0:3000/        |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |     ReplicaSet OpLog: Enabled                     |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |          Commit Hash: b471caf9c9                  |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |        Commit Branch: HEAD                        |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ |                                                   |
Nov 27 10:06:20 chat rocketchat[28294]: ➔ +---------------------------------------------------+

Step 6 – Configure Nginx Reverse Proxy

Configure Nginx to act as reverse proxy. We’ll also setup Let’s Encrypt in the same configuration file

Install Nginx web server:

sudo apt install nginx

Use the configuration below for reverse proxy setup before setting up SSL.

sudo nano /etc/nginx/conf.d/rocketchat.conf

The file will have contents similar to this:

upstream rocket_backend {
  server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name chat.hirebestengineers.com;
    access_log /var/log/nginx/rocketchat-access.log;
    error_log /var/log/nginx/rocketchat-error.log;

    location / {
        proxy_pass http://rocket_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-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }
}

Where:

  • rocket.example.com is to be replaced with the domain name

Check if Nginx configuration is ok.

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

Restart and enable Nginx service

sudo systemctl restart nginx
sudo systemctl enable nginx

Step 7 – Setup Let’s Encrypt SSL

Download and setup Let’s Encrypt for SSL certificate

sudo apt install certbot python3-certbot-nginx

Then run certbot to acquire SSL certificate

$ sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: chat.hirebestengineers.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for chat.hirebestengineers.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/chat.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/chat.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://chat.hirebestengineers.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=chat.hirebestengineers.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/chat.hirebestengineers.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/chat.hirebestengineers.com/privkey.pem
   Your cert will expire on 2021-02-26. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

The final Nginx configuration after SSL should look like:

upstream rocket_backend {
  server 127.0.0.1:3000;
}

server {
    server_name chat.hirebestengineers.com;
    access_log /var/log/nginx/rocketchat-access.log;
    error_log /var/log/nginx/rocketchat-error.log;

    location / {
        proxy_pass http://rocket_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-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/chat.hirebestengineers.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/chat.hirebestengineers.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
    if ($host = chat.hirebestengineers.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name chat.hirebestengineers.com;
    return 404; # managed by Certbot
}

Check if Nginx configuration is ok.

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

Restart and enable Nginx service:

sudo systemctl restart nginx

Your chat server should now be accessible via your FQDN with https.

Configure your server using the setup wizard

rocket chat ubuntu 20.04

After successful configuration of the server, the site can now be accessed using the admin credentials you created in the previous step.

install rocketchat ubuntu 20.04

We have successfully installed Rocket.Chat on Ubuntu 20.04 server and configured it.

Updating Rocket.Chat

To update Rocket.Chat, follow the steps below:

  1. Stop Rocket.Chat service
sudo systemctl stop rocketchat

Remove the current installation in /opt

sudo rm -rf /opt/Rocket.Chat

Make sure you have the necessary dependencies and build packages

sudo apt-get install -y build-essential  graphicsmagick

Download the latest version of Node.js supported by Rocket.Chat

$ sudo n install 12.18.4
  installing : node-v12.18.4
       mkdir : /usr/local/n/versions/node/12.18.4
       fetch : https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-x64.tar.xz
   installed : v12.18.4 (with npm 6.14.6)

Download and extract the latest version of Rocket.Chat

sudo curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
sudo tar -xzf /tmp/rocket.chat.tgz -C /tmp

Install the latest version of Rocket.Chat

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

Set the correct permissions to the Rocket.Chat directory

sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat

Start the Rocket.Chat service

sudo systemctl start rocketchat

Confirm service status:

$ systemctl status rocketchat
● rocketchat.service - The Rocket.Chat server
     Loaded: loaded (/etc/systemd/system/rocketchat.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-07-12 19:46:12 UTC; 10s ago
   Main PID: 21028 (node)
      Tasks: 11 (limit: 2344)
     Memory: 439.5M
     CGroup: /system.slice/rocketchat.service
             └─21028 /usr/local/bin/node /opt/Rocket.Chat/main.js

Jul 12 19:46:12 ubuntu systemd[1]: Started The Rocket.Chat server.
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |      MongoDB Version: 4.4.6                   |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |       MongoDB Engine: wiredTiger              |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |             Platform: linux                   |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |         Process Port: 3000                    |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |             Site URL: http://localhost:3000/  |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |     ReplicaSet OpLog: Enabled                 |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |          Commit Hash: e178a9a254              |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |        Commit Branch: HEAD                    |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ |                                               |
Jul 12 19:46:37 ubuntu rocketchat[21028]: ➔ +-----------------------------------------------+

Cheers and thanks for following through this article.

You can now check out other related articles below:

How To Install Rocket.Chat Server on Debian / Ubuntu

Install Chatwoot on Ubuntu with Let’s Encrypt SSL

Video Courses to Learn Linux Systems:

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

5 COMMENTS

  1. This is great – thanks a lot!
    One question though:
    What would be the workaround, if I already have another machine in my network (like Exchange) where Port 80 is in use for?

    I guess it is still required with your tutorial, to have a port forward to Port 80 for Certificate extension, right?

    Any ideas?

LEAVE A REPLY

Please enter your comment!
Please enter your name here