When Macaulay2 is successfully installed, its files are installed in a directory tree whose layout, relative to the root, is determined by the hash table Layout. When M2 starts up, it detects whether it is running in such a layout, and sets prefixDirectory to the root of that directory tree. The way it does that is that it locates the running M2 executable and determines whether it is located in a directory whose name is bin that has a sibling directory called share that leads to a directory called share/Macaulay2/Core/.
The prefix directory can be set by the user at an early stage when M2 starts up with the --prefix command line option. This will affect the value of path and thus the locations of the files loaded initially. Use the --notify command line option to display the locations of files as they are loaded.
The object prefixDirectory is a string.