Install Mattermost on Ubuntu 20.04

Updated on March 1, 2022
Install Mattermost on Ubuntu 20.04 header image


Mattermost is a free and open-source platform for developer collaboration and messaging. It's secure, flexible, and comes with a wide variety of tools to develop better workflows. Some notable features are two-factor authorization, video calls, file sharing capabilities, webhooks support, multi-threaded messaging, fully responsive user interfaces, and so on. Mattermost is an alternative to Slack. This article explains how to install Mattermost on Ubuntu 20.04.


1. Install PostgreSQL Server

Update the system packages.

$ sudo apt update

Install PostgreSQL database server.

$ sudo apt -y install postgresql-12 postgresql-contrib

Enable the database server to start automatically on system startup.

$ sudo systemctl enable postgresql

Start the database server.

$ sudo systemctl start postgresql

2. Create Mattermost Database

Secure PostgreSQL by changing the default PostgreSQL password.

$ sudo passwd postgres

Switch to the postgres user.

$ su - postgres

Create a new database user named mattermostuser.

$ createuser mattermostuser

Log in to the PostgreSQL instance.

$ psql

Set a secure password SecurePassword for the user.

ALTER USER mattermostuser WITH ENCRYPTED password 'SecurePassword';

Create a database named mattermost and set the owner to mattermostuser.

CREATE DATABASE mattermost OWNER mattermostuser;

Grant all the privileges on the database to the user.

GRANT ALL PRIVILEGES ON DATABASE mattermost to mattermostuser;

Exit PostgreSQL instance.


Return to your non-root sudo user account.

$ exit

3. Install Mattermost

Create a system user and group called mattermost.

$ sudo useradd --system --user-group mattermost

Download the latest version of Mattermost. Please visit the official releases page to get the latest release.

$ wget

Extract the downloaded archive.

$ sudo tar xvf mattermost-6.4.0-linux-amd64.tar.gz

Move the extracted file to the /opt directory.

$ sudo mv mattermost /opt

Remove the downloaded archive.

$ sudo rm mattermost-6.4.0-linux-amd64.tar.gz

Create the storage directory.

$ sudo mkdir -p /opt/mattermost/data

Set correct ownership and permissions.

$ sudo chown -R mattermost:mattermost /opt/mattermost

Give write permissions to the Mattermost group.

$ sudo chmod -R g+w /opt/mattermost

4. Configure Mattermost Server

Edit the configuration file to set up the database driver.

$ sudo nano /opt/mattermost/config/config.json

Locate SqlSettings section and configure PostgreSQL database settings like bellow.

"DriverName": "postgres",
"DataSource": "postgres://mattermostuser:SecurePassword@localhost:5432/mattermost?sslmode=disable&connect_timeout=10",

Create Mattermost systemd service unit.

$ sudo nano /etc/systemd/system/mattermost.service

Add the below code into the file. Then, save and close the file:

Description=Mattermost Server



Reload systemd daemon for changes to take effect.

$ sudo systemctl daemon-reload

Start the Mattermost service.

$ sudo systemctl start mattermost

Enable the service to run on system startup.

$ sudo systemctl enable mattermost

Check service status.

$ systemctl status mattermost

Allow associated ports.

$ sudo ufw allow 8065/tcp

$ sudo ufw allow 80/tcp

5. Create Reverse Proxy

Test the web interface, go to your browser and visit http://Server_IP:8065. For example:

Install Nginx server.

$ sudo apt install -y nginx

Unlink Nginx default configuration file.

$ sudo unlink /etc/nginx/sites-enabled/default

Create new Nginx configuration file for named mattermost.conf.

$ sudo nano /etc/nginx/sites-available/mattermost.conf

Add the following code to the file. Save and close the file.

server {
    listen 80;

    location / {
        proxy_pass http://localhost:8065;

Enable the new configuration file.

$ sudo ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.conf

Restart the Nginx service.

$ sudo service nginx restart

You can now access the web interface without using a port. Go to your browser and visit http://Server_IP. For example:


You have installed Mattermost on your Ubuntu 20.04 server. Access the installation page create your administrator account. You can now begin creating workflows.

More Information

To learn more about how to use Mattermost, go to the official documentation page.