How to Install Mattermost on Ubuntu 18.04

This article will cover the installation of Mattermost on an Ubuntu 18.04 Linux server. Mattermost is an open-source, self-hostable online chat service with file sharing, search, and integrations. It is designed to be used as an internal chat for organizations and companies and could be considered an open-source alternative to Slack and Microsoft Teams.


Access to a Linux server running Ubuntu 18.04


This part of the article will walk you through installing Mattermost and it’s dependencies.

Part One: Installing the MySQL Database

1) Log into your Ubuntu 18.04 server as root or a sudo user

2) Run the following command to install MySQL:

# sudo apt install mysql-server

3) Execute the command below to go through the Secure Installation. Follow the prompts provided by the wizard:

# sudo mysql_secure_installation

4) Now we need to log into MySQL as root using the following:

#sudo mysql

5) Once you see ‘mysql>’ in the prompt, you’ve entered the database. Now we need to create a user and password. Execute the following commands, but replace mmuser and mmuser-password with unique identifiers:

create user 'mmuser'@'%' identified by 'mmuser-password';

Also, it’s worth noting that the % indicates that this user can connect from a device with any IP address. If you know the IP this user will be connecting from, it’s more secure to change the % to that IP address.

6) While we’re still in the MySQL prompt, we need to create a database and grant permissions to that database for our new user. The commands below will accomplish this:

create database mattermost;
grant all privileges on mattermost.* to 'mmuser'@'%';

7) Now that we’ve installed and set up our database, we can exit MySQL to get back to the Linux command prompt by running the command below:


Part Two: Installing Mattermost

1) Download the latest version of the Mattermost Server. Navigating to this URL and scrolling down should display a URL just below the ‘GET DOWNLOAD’ button. Copy this URL and within your server’s terminal execute the following command:


In our example, we’ve replaced version numbers with X’s, but the URL you copied should contain these version numbers.

2) Now we need to extract the files we’ve downloaded using the following:

tar -xvzf mattermost*.gz

3) Once we’ve extracted the files, we need to move them to the /opt directory using the command below:

sudo mv mattermost /opt

4) Next, we need to make the directory where we’ll store the files:

sudo mkdir /opt/mattermost/data

5) We’ll need to create a user dedicated to the Mattermost service, which will be the one running Mattermost and owner of the related files and directories. The following commands will create the user, group, and set the permissions:

sudo useradd --system --user-group mattermost

sudo chown -R mattermost:mattermost /opt/mattermost

sudo chmod -R g+w /opt/mattermost

6) Next, we’ll have to set up the database driver in the file /opt/mattermost/config/config.json by making some changes to its contents. Open the file in your preferred text editor and then look for and adjust the following values:

  • Set “DriverName” to “mysql”
  • Set “DataSource” to the following value “mmuser:mmuser-password@tcp(:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s”
  • Set “SiteURL” to the full URL you plan to use for your Mattermost site. You need to include http:// or https://

Be sure on the “DataSource” edit that you only change the to the public IP of your server if the database is remote to the server where Mattermost is installed. If they live on the same server, then set it to localhost:3306

7) Now we’ll test out our Mattermost application. Navigate to the following directory:

cd /opt/mattermost

    And run the following command to start Mattermost:

sudo -u mattermost ./bin/mattermost

    When the server starts, it shows some log information and the text Server is listening on :8065. You can stop the server by pressing CTRL+C in the terminal window.

8) Now that we’ve confirmed the server starts without issue, we need to configure Mattermost to use systemd for starting and stopping. First, we’ll create a new systemd unit file using the following command:

sudo touch /lib/systemd/system/mattermost.service

9) Now open that file in your text editor and paste the following into the file. Once you’ve made the change, save the file and exit:




10) Now we need to make systemd load the new unit and we’ll use systemctl to test our new unit file:

sudo systemctl daemon-reload

sudo systemctl status mattermost.service

You should see an output similar to the following:

● mattermost.service - Mattermost
  Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
  Active: inactive (dead)

11) If you receive the expected response, we can start the service:

sudo systemctl start mattermost.service

12) Now, test and see whether the service is running:

curl http://localhost:8065

You should see the HTML that’s returned by the Mattermost server.

13) Finally, we can set Mattermost to start on boot:

sudo systemctl enable mattermost.service

From here on, most of the configuration will be handled within the browser on the Mattermost site itself and it’s provided panel. You can navigate to http://your-url-for-mattermost:8056 and follow the prompts to configure your first Mattermost user, which will be granted administrator privileges. You can continue using the Mattermost panel to configure Mattermost for your team’s needs. This is where you’ll be able to set up things like users, email notifications, image and file storage location, and assigning administrators for Mattermost. For further reading on Mattermost, please refer to their official knowledge base.