How to Change Localhost File on Mac
Follow these steps to change localhost file on Mac:
1. Open Terminal.
2. Type the following command: sudo nano /etc/hosts, then press ‘Enter’.
3. This will request your password. Type in your account password, then press ‘Enter’.
4. This will show the contents of your local host file.
5. Underneath the text ::1 localhost, type in the IP address of your server and the name of your website. Syntax as follows: (IP Address) (Domain Name)
Always type two entries for the one domain name, ie. www.example.com followed by example.com.
6. You can add # in front of your entry. This will turn the text into a string and won’t be read by the system.
Very convenient to switch between the server you are working on and the server your domain is pointing to.
7. Once you have typed in your entries, press ‘Ctrl and X’ at the same time to exit the file. It will then request if you wish to save your changes. Press ‘Y’ for Yes, ‘N’ for No, or ‘Ctrl and C’ to Cancel.
8. It will ask to confirm the file name to write the changes to. Press ‘Enter’ to save those changes.