So you have installed elementary OS in a hurry only to realize you made a typo or gave a weird name or left the default name having the PC maker and model for the computer name? Just my guess! You didn’t bother it much until you start seeing it in the Terminal’s command prompt.
In this mini-tutorial, we show you how quick it to change the computer name on your elementary OS PC. To achieve what we want, we shall edit the hostname in the system file using “gedit” command, and also configure the hosts file too so that you don’t get “unable to resolve host” error message when using the “su” or “sudo” command.
Changing the PC name
STEP 1: Click on ‘Applications’ and launch ‘Terminal’.
STEP 2: Type the following command line and hit enter.
sudo gedit /etc/hostname
As you can notice, we are using gedit to edit the hostname file. Just for the unware, gedit is the default text editor of the GNOME desktop environment and part of the DE’s core Applications. All Ubuntu and derivatives should have it installed by default. For some reason, if your elementary OS shows gedit is not installed, fire the following command in the terminal to install it.
sudo apt-get install gedit
STEP 3: You should see a new window with the current computer name in it. In my test PC, the name is ‘FOSSLinux’. I will change it to ‘PC_NAME_CHANGE’ just for the sake of this tutorial. You can enter whatever the new name you want.
STEP 4: When done, click ‘Save’.
STEP 6: Finally, update the new name in the hosts file too in a similar way with the following command. (Thanks to cleteman in the comments below.)
sudo -i gedit /etc/hosts
STEP 7: Close everything and restart the computer.
STEP 8: Launch ‘Terminal’ to see your new computer name in the command prompt.
6 comments
One more step:
Update the /etc/hosts file with the new hostname.
Other wise you will get an “unable to resolve host” msg when using su or sudo cmd.
My bad – missed it. Thanks for highlighting it. I have included it.
Kiran,
Thank you for your insights on all things Linux. They are very informative and helpful. Keep up the good work 🙂
Thank you! Saved me from having to do a re-install 🙂
command below worked for me without gedit installation:
pkexec io.elementary.code /etc/hostname
Hey,
after following your instructions the name has been successfully changed, visible in the terminal. Nonetheless, the old name still is potrayed/used in the context of bluetooth connection. Do you know, why? How may it be changed?
Thank you in advance!