MacOS – How to save root aliases permanently

bashmacmacbook promacosterminal

i tried saving aliases (see below) for the root user in .bash_profile to /var/root/.bash_profile and restarting Terminal, but it didn't work. where does the .bash_profile file need to be to maintain persistent aliases in the terminal?

$ cat /var/root/.bash_profile
alias grep='grep --color=always'
alias net='sudo netstat -ap tcp && sudo lsof -Pn -i4'

my specifications:

sh-3.2# system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: OS X 10.8.5 (12F45)
      Kernel Version: Darwin 12.5.0
      Boot Volume: lily
      Boot Mode: Normal
      Computer Name: lily’s MacBook Air
      User Name: System Administrator (root)
      Secure Virtual Memory: Enabled
      Time since boot: 12:37

Best Answer

The proper config file name of the standard root shell (i.e. sh) is .profile. So change the name of .bash_profile to .profile:

mv /var/root/.bash_profile /var/root/.profile
source /var/root/.profile

This is working logging in as root in the GUI.


Trying to sudo su in a sudoer's shell won't fetch root's .profile file. Use sudo -i instead.