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:
- Homebrew (a package manager for macOS)
- Docker Desktop (a desktop application for Docker)
Steps
Here are the steps to install GoatCounter on macOS:
Open the
Terminalapp on your macOS system.Install the
goatcounter/clipackage using Homebrew by running the following command:brew install goatcounter/cli/goatcounterYou can verify that GoatCounter is installed by running the following command:
goatcounter versionThis should output the version of GoatCounter that you have installed on your system.
Next, you need to create a configuration file for GoatCounter. You can either create a
goatcounter.conffile in the current directory or in the directory where you want to store the configuration file.Here is an example of a
goatcounter.conffile:[server] addr = ":8080" [pg] host = "postgres" user = "postgres" passfile = "/run/secrets/goatcounter-postgres-password" name = "goatcounter" [smtp] host = "smtp.gmail.com" port = 587 user = "[email protected]" passfile = "/run/secrets/goatcounter-smtp-password" from = "[email protected]" to = ["[email protected]"] subject = "{{ .Domain }} activity"Note: Replace the email addresses and passwords with your own email and password.
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-alpineNext, 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-passwordwith your own password.Run the following command to create the SMTP password secret:
echo "your-password" | docker secret create goatcounter-smtp-password -Replace
your-passwordwith your own password.Finally, you can start GoatCounter by running the following command:
goatcounter serve -listen ":80" -tls none -config goatcounter.confThis will start GoatCounter on port
80and 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.