Ubuntu is not idiot-proof. You won’t get Mac-like experience in this Linux distribution. Instead, you will get Windows-like experience with an opportunity to solve one problem at a time without yelling toward Seattle.
Whenever you run a sudo command, the terminal returns an error message, “sudo: unable to resolve host”. This is the hostname issue. For me, this occurs most frequently thanks to Parallels. The virtual machine software automatically install a copy of Ubuntu with a hostname “parallels-vm”. There are multiple Parallels-based VM on the network, so leaving it as-is is not an option.
- Open Terminal.
- Run following command and make note of the current hostname:
- Run following command to edit the hostname:
sudo nano /etc/hosts
- Replace the current hostname, shown as bracketed, with your desired hostname:
127.0.0.1 localhost 127.0.1.1 [New Hostname]
- Run following command and replace the hostname to a new one:
sudo nano /etc/hostname
- Run the following to reboot and check if the changes survived.
If you cannot afford to reboot the system, you can simply run “hostname” command alone. But note that this will not survive the reboot.
I believe this is one of the occasions why I simply cannot recommend Ubuntu for the sake of accessibility. Any GUI-familiar users would expect the system settings to have some ways to handle hostname; both Windows and Mac have some form of it. And mosts users would expect the changes to be made system wide when a dedicated command is run. If an operating system is designed with GUI in mind, the bare minimum of that interface is to be streamlined enough so that the users do not have to jump back to CLI to make simple changes.
updated Jul 20, 2018: edited for better readability.