How to Install GoatCounter on macOS

GoatCounter is a simple and privacy-friendly web analytics tool that can be self-hosted. In this tutorial, you will learn how to install GoatCounter on macOS.

Prerequisites

Before you start, you need to make sure that you have the following prerequisites installed on your macOS system:

Steps

Here are the steps to install GoatCounter on macOS:

  1. Open the Terminal app on your macOS system.

  2. Install the goatcounter/cli package using Homebrew by running the following command:

    brew install goatcounter/cli/goatcounter
    
  3. You can verify that GoatCounter is installed by running the following command:

    goatcounter version
    

    This should output the version of GoatCounter that you have installed on your system.

  4. Next, you need to create a configuration file for GoatCounter. You can either create a goatcounter.conf file in the current directory or in the directory where you want to store the configuration file.

    Here is an example of a goatcounter.conf file:

    [server]
    addr = ":8080"
    
    [pg]
    host = "postgres"
    user = "postgres"
    passfile = "/run/secrets/goatcounter-postgres-password"
    name = "goatcounter"
    
    [smtp]
    host = "smtp.gmail.com"
    port = 587
    user = "youremail@gmail.com"
    passfile = "/run/secrets/goatcounter-smtp-password"
    from = "youremail@gmail.com"
    to = ["youremail@gmail.com"]
    subject = "{{ .Domain }} activity"
    

    Note: Replace the email addresses and passwords with your own email and password.

  5. Now you need to start a Docker container with PostgreSQL for the database. You can do this by running the following command:

    docker run -d --name goatcounter-postgres \
        -e POSTGRES_USER=postgres \
        -e POSTGRES_PASSWORD_FILE=/run/secrets/goatcounter-postgres-password \
        -e POSTGRES_DB=goatcounter \
        -v goatcounter-postgres-data:/var/lib/postgresql/data \
        -v goatcounter-postgres-secrets:/run/secrets \
        --restart=always \
        postgres:13-alpine
    
  6. Next, you need to create the secrets for the PostgreSQL password and the SMTP password.

    Run the following command to create the PostgreSQL password secret:

    echo "your-password" | docker secret create goatcounter-postgres-password -
    

    Replace your-password with your own password.

    Run the following command to create the SMTP password secret:

    echo "your-password" | docker secret create goatcounter-smtp-password -
    

    Replace your-password with your own password.

  7. Finally, you can start GoatCounter by running the following command:

    goatcounter serve -listen ":80" -tls none -config goatcounter.conf
    

    This will start GoatCounter on port 80 and use the configuration file that you created earlier.

Conclusion

Congratulations! You have successfully installed GoatCounter on macOS using Docker and Homebrew. You can now use GoatCounter to track the visitors to your website.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!