Change computer name

Just after installing a new version of OS X you just realized you don't like the name of your computer?. No problem just go to Preferences > Sharing and change it:

But then you go to Terminal.app and realized that your prompt still has the old name :(. That is because the default terminal prompt uses the hostname. Doing above things does not change the hostname.

You could change the prompt by modifying $PS1 variable but that will not solve the problem as the kernel hostname would still have the old name.

Change the Hostname

To change it we use sysctl kern.hostname=NEW_NAME
$ hostname

$ sudo sysctl kern.hostname=IgnacioMBP
kern.hostname: Ignacio-no-MacBook-Pro.local -> IgnacioMBP

$ hostname
To confirm current value we use hostname command. Now we have to restart the terminal so the new hostname is read again populating $PS1 as intended :)

See also:
MDLog:/sysadmin - How to change the hostname of a Linux system