How to Install GoatCounter on Elementary OS Latest

GoatCounter is a privacy-focused web analytics platform. In this tutorial, we will learn how to install GoatCounter on Elementary OS (latest version). The steps are as follows:

1. Update Your System

Before installing any new software on your system, make sure you have the latest updates installed. Use the following commands to update your system:

$ sudo apt update
$ sudo apt upgrade

2. Install Dependencies

GoatCounter is built with Go programming language, so we need to install the Go compiler and other dependencies. Use the following command to install them:

$ sudo apt install golang-go build-essential

3. Download and Install GoatCounter

Now, we need to download and install GoatCounter. Use the following commands to download and install it:

$ go get github.com/goatcounter/goatcounter

$ cd ~/go/src/github.com/goatcounter/goatcounter

$ make

Note: If you get an error like "command not found", it means that the Go bin directory is not in your system's PATH. You can fix this by adding the following line to your .bashrc file:

export PATH=$PATH:/usr/local/go/bin

4. Configure GoatCounter

After installing GoatCounter, you need to configure it. Use the following command to generate a configuration file:

$ goatcounter dbcreate --config /etc/goatcounter.conf

Next, open the configuration file using a text editor of your choice:

$ sudo nano /etc/goatcounter.conf

In this file, you need to specify the domain name you want to track, along with your database credentials. You can find more information about the configuration file in the GoatCounter documentation.

5. Start GoatCounter

Now that we have installed and configured GoatCounter, we can start the service using the following command:

$ goatcounter serve --config /etc/goatcounter.conf

This will start the GoatCounter web server on port 8080. You can now access the web interface by visiting http://localhost:8080 in your web browser.

6. Setting up a Systemd service

Step 5 shows how to start GoatCounter, but if we restart the system it won't start automatically. For that we need to set a systemd unit file.

  • Create /etc/systemd/system/goatcounter.service and add the following lines:
[Unit]
Description="GoatCounter server"
After=syslog.target network-online.target

[Service]
Type=simple
ExecStart=/home/<YOUR_USERNAME>/go/bin/goatcounter serve --config /etc/goatcounter.conf -listen=":9090"
Restart=always
RestartSec=3
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=GoatCounter

[Install]
WantedBy=multi-user.target
  • Then enable the service by the command: sudo systemctl enable goatcounter.service
  • The /home/<YOUR_USERNAME>/go/bin/goatcounter serve --config /etc/goatcounter.conf -listen=":9090" depends on:
    • The $GOPATH/bin directory is in your PATH variables
    • The service must be updated in the specific situation.

After completing the aforementioned steps successfully, GoatCounter will be installed and configured properly on your system.