Setup Instructions for macOS
Installing R and RStudio
For Mac users, the R project provides specific installers that are available at https://cloud.r-project.org/. Download the latest installer for your system (version 4.1 is recommended), execute it by double-clicking on the file, and follow the installation instructions.
To install RStudio, go to the RStudio website. There are different versions, the “free” version is sufficient for our purpose. Download the installer, run this file and follow the installation instructions. You should now have R and RStudio installed on your computer.
Installing PostgreSQL and the PostGIS extension
To run the PostgreSQL database server on a Mac, we rely on the excellent Postgres.app installer. This is a pre-packaged version of the (open-source) PostgreSQL database system and makes the installation extremely convenient for Mac users.
Download the installer from the Postgres.app website. We recommend that you choose the latest version of Postgres.app, which includes version 14 of the PostgreSQL database server. Conveniently for our purpose, Postgres.app contains also the PostGIS spatial extension for PostgreSQL, which we need in the chapter on spatial data. Run the installer by double-clicking the file you downloaded and simply drag-and-drop Postgres.app into your “Applications” folder.
Once this is done, you can run Postgres.app just like any other Mac application, simply by double-clicking on it in the “Applications” folder. The first time you do this you need to initialize a new server, as this is not done automatically. When you start Postgres.app, the following window comes up:
At the bottom right, click “Initialize” to configure a new server. You can simply leave the default values for the server name etc (unless you already have PostgreSQL or another server running on port 5432, which is unlikely). The new server is started automatically, and you can now close the Postgres.app main window. If you later want to start/stop the new server, you can do this through Postgres.app or the elephant icon in the main menu bar.
When we later connect to our new server from R, we need to provide a user name and a password. Postgres.app automatically configures the server such that is uses your (short) Mac username for this purpose. If you’re unsure what this username is, see Apple’s instructions to find out. By default, there is no password for this user.
You now have running PostgreSQL server on your system. For the exercises in the book, it is important that you remember the name of the user:
''(or anything else, since it’s not used in the default configuration)
Whenever we connect to the database server in the chapters of the book, username and password must be set correctly, otherwise the connection will fail. In our examples, we assume that you left the default port (
5432) unchanged, and that you installed PostgreSQL on your local machine (which is referred to as
localhost). If this is not the case and for some reason you deviate from this standard configuration, you will have to adjust these parameters for the DB connections in the code examples.
Please note: We are installing the PostgreSQL server here with a minimal configuration and solely for the purpose of running the exercises in the book. If you plan to use the server together with other users, such that it can be reached also from other machines, some more configuration is required to enable this and to properly secure the server. The configuration presented here is not intended for this purpose.
Instructions for removing Postgres.app from your system are provided here.