Deploy with Ubuntu
    • Dark
      Light
    • PDF

    Deploy with Ubuntu

    • Dark
      Light
    • PDF

    Article summary

    Rocket.Chat offers several deployment options, one of which is on Ubuntu. Whether you’re new to server administration or an experienced professional, this document will provide a step-by-step walkthrough to set up a secure and efficient Rocket.Chat environment on Ubuntu.

    Prerequisites

    For any Rocket.Chat version you want to install, check the release notes to see the supported engine versions for MongoDB and NodeJs, and install as recommended.

    Install Node.js

    Follow the official guide to install NodeJS on Ubuntu, or use third-party tools like nvm or n for easier version management.

    Install Deno

    Deploying Rocket.Chat requires Deno.  

    Only Deno versions >=1.37.1 and <2.0.0 are supported.

    Follow the official Deno installation guide to install the correct version.

    Set up MongoDB

    When deploying MongoDB, it is crucial to secure MongoDB instances by restricting public access to all MongoDB ports. Unsecured instances can create serious security vulnerabilities, so taking these precautions is critical to ensuring the integrity and safety of your systems.

    1. Start by installing MongoDB on Ubuntu. Refer to the official MongoDB documentation for the latest installation instructions

    2. Once MongoDB is installed, open the MongoDB configuration file (/etc/mongod.conf) by running:

      nano /etc/mongod.conf
    3. In this file, enable replication and specify the replica set name as rs01

      The MongoDB replica set is mandatory for Rocket.Chat > 1.0.0.

      Your MongoDB configuration file should look something like the below:

      # mongod.conf
      
      # Where and how to store data.
      storage:
        dbPath: /var/lib/mongodb
      
      # where to write logging data.
      systemLog:
        destination: file
        logAppend: true
        path: /var/log/mongodb/mongod.log
      
      # network interfaces
      net:
        port: 27017
        bindIp: <bind-ip> # Replace with your IP address
      
      
      # how the process runs
      processManagement:
        timeZoneInfo: /usr/share/zoneinfo
      
      # Replication settings
      replication:
        replSetName: rs01

      Refer to the official MongoDB configuration documentation for additional configuration options.

    4. Start MongoDB with this command:

      sudo systemctl enable --now mongod
    5. Next, initialize the replica set:

      mongosh --eval "printjson(rs.initiate())"
    6. To ensure MongoDB is running successfully, run this:

      sudo systemctl status mongod

    With all the prerequisites in place, you're ready to install Rocket.Chat.

    Step 1: Install Rocket.Chat on Ubuntu

    1. Install the required packages and dependencies

      sudo apt install -y curl build-essential graphicsmagick
    2. Check the Rocket.Chat release document to choose the version you need. For stability and compatibility, we recommend downloading a specific version. For example, to download version 6.13.0, run this command:

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

      Alternatively, if you prefer to download the latest version, you can use the following command:

      curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
    3. Extract the Rocket.Chat server files using this command:

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

      This command extracts the contents of the downloaded “rocket.chat.tgz” compressed tar archive located in the /tmp directory and places the extracted files into the same /tmp directory.

    4. Next, run the command below to change the current directory and install the necessary production dependencies.

      cd /tmp/bundle/programs/server && npm install --production

      When executing npm install, it is recommended to operate using a non-root account. Alternatively, you can utilize the npm install --unsafe-perm --production command. This approach eliminates the necessity for building libc or upgrading the host system.

    5. Move the extracted files to the /opt directory.

      sudo mv /tmp/bundle /opt/Rocket.Chat

      This guide uses the /opt directory. However, you can choose your preferred directory.

    Step 2: Configure the Rocket.Chat service

    1. Start by adding the Rocketchat user and setting the right permissions on the Rocket.Chat folder.

      sudo useradd -M rocketchat && sudo usermod -L rocketchat
      sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat
    2. Depending on how you install NodeJS, the binary path may be different. Save the path to a variable.

      NODE_PATH=$(which node)
    3. Now, save the systemd service file.

      cat << EOF |sudo tee -a /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=$NODE_PATH /opt/Rocket.Chat/main.js
      StandardOutput=journal
      StandardError=journal
      SyslogIdentifier=rocketchat
      User=rocketchat
      [Install]
      WantedBy=multi-user.target
      EOF

      The command above will create a barebone service file, which the system will use to start your Rocket.Chat daemon/process.

    Step 3: Passing environment variables

    Running the Rocket.Chat daemon requires passing some environment variables. See Rocket.Chat environmental variables for more details.

    • Update the Rocket.Chat file by running:

      sudo systemctl edit rocketchat
    • Next, update the file with the information below and save it.

      [Service]
      Environment=ROOT_URL=http://localhost:3000
      Environment=PORT=3000
      Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01
      Environment=MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01

    Additional steps for installing 6.10 release

    If you’re installing version 6.10, run these additional commands:

    mkdir -p /home/rocketchat/.cache
    
    cd PATH_TO_ROCKETCHAT_INSTALLATION/programs/server/npm/node_modules/@rocket.chat/apps-engine
    
    export DENO_DIR=/home/rocketchat/.cache/deno
    
    npm install --production
    
    npm run postinstall
    
    chown -R rocketchat:rocketchat /home/rocketchat
    • Now, start your Rocket.Chat workspace using this command:

      sudo systemctl enable --now rocketchat

      If you edit your Rocket.Chat configuration file, make sure to reload the daemon and restart the Rocket.Chat process by running the following commands:

      sudo systemctl daemon-reload
      sudo systemctl restart rocketchat

      You can also check the status of the Rocket.Chat process with this command:

      sudo systemctl status rocketchat

    Step 4: Configure your Rocket.Chat server

    • To access your Rocket.Chat workspace, open a web browser, and navigate to the "ROOT URL" you specified in the Rocket.Chat configuration file. This is typically accessible at http://your-host-name.com:3000.

    • Follow the on-screen prompts to configure your workspace.

    Optional configurations

    Apply the following optional configurations to your Rocket.Chat setup enhanced security and performance:


    Was this article helpful?