The hosts file is found in a different location in every operating system, and needs to be edited in a different way.

See this table for the all the information in short, and click on an any operating system name for more detailed explanations on where to find the hosts file and how to edit it in that system.