All Unix-like operating systems I've seen use /root as the home directory for the root account. What's the reason it was moved to /var/root in macOS? Can I change it to the usual /root?
I need to run some scripts on macOS which hardcode /root as the root's home directory. Also, I thought that /var was for variable data (spool, log files, etc.).

  • 1
    You are skating close to a question that asks someone to divine why Apple does a thing. Which could get your question deleted because we deal in facts and not guessing why a company does something.. If you expand your question with what you are trying to accomplish it might help. – Steve Chambers Oct 17 '18 at 16:00
  • Also why do you think it should be /root? – Mark Oct 17 '18 at 16:32
  • 1
    If the scripts hardcode root what other non standard things do they do which will fail on macOS? – Mark Oct 17 '18 at 17:54
  • 2
    ln -s /var/root /root # but then you still have to worry about Mark's comment. If you fully understand the script, why not edit it to work? If you don't understand it, do you really want to run it with root privilege? – WGroleau Oct 17 '18 at 18:37

A simple solution would use tilde expansion in the scripts instead of a hard coded location.


ls -ld ~root
  • But what else is hardcoded - you need to read every line of that script to check it especially as it runs as root so could do anything – Mark Oct 18 '18 at 12:07

I think the problem is that you haven't really seen that many Unix-like operating systems. Traditionally with Unix-like operating systems, you would actually have the root user's home directory at /.

If you have worked with Linux or perhaps FreeBSD, you would expect the root user's home directory to be at /root - but it's not really "God-given".

There's plenty examples of Unix-like operating systems that use varying locations. For example on HP-UX systems you wouldn't blink an eye to find the home directory at /homeroot. Similarly on macOS it is at /var/root.

Regarding your assumption on the use of the /var folder: Traditionally there hasn't been any kind of hard consensus on what each of the traditional system folders are used for (for example /etc, /usr, /usr/local, /lib, /etc.). This might vary from operating system to operating system.

Usually you would say that the /var folder is for variable data - however that doesn't mean that it is limited to spool or log files, like you write. It means that the contents of the folder might change while using your system - in contrast to for example /bin, where traditionally you could assume that this folder could just be reinstalled from the original installation medium. In this sense the root user's home folders fits the description. You usually don't want it in /home or /Users as that could be a networked file system, and you traditionally wanted the root user to be able to always be able to login for system recovery.

On macOS you can change the location of the root user's home directory. For recovery purposes, change the location in /etc/passwd. For ordinary usage, change it in the Open Directory.

You can see the current settings with:

dscl . -read Users/root | grep NFSHomeDirectory

And change them with:

dscl . -change Users/root NFSHomeDirectory <old> <new>

where and are replaced with the relevant paths.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .