How to change computer name so terminal displays it in Mac OS X Mountain Lion? [duplicate]

If you use:

sudo scutil --set HostName name-you-want

it will work a bit better. From the scutil(8) man page:

--get pref
    Retrieves the specified preference.  The current value will be
    reported on standard output.

    Supported preferences include:
          ComputerName   The user-friendly name for the system.
          LocalHostName  The local (Bonjour) host name.
          HostName       The name associated with hostname(1) and gethostname(3).

--set pref [newval]
    Updates the specified preference with the new value.  If the new value is not
    specified on the command line then it will be read from standard input.

    Supported preferences include: ComputerName LocalHostName HostName

    The --set option requires super-user access.

After following Jeffrey J. Hoover's tip,

sudo scutil --set ComputerName "newname"
sudo scutil --set LocalHostName "newname"
sudo scutil --set HostName "newname"

I would add these last two steps.

  • Flush the DNS cache by typing: dscacheutil -flushcache
  • Restart your Mac.

EDIT: It didn't work for me until I restarted my mac.