When you’re developing locally, whether you’re using MAMP, XAMP or Vagrant, at some point you might need to give a special name to your local development environment.

Because why not?

I mean it’s totally okay to go to http://192.168.33.10 but why not make it http://mijimo.local or http://www.mijimo.dev

To do that, we need to edit our hosts file on our Mac.

It’s a pretty easy and straightforward task. Here’s how to do it.

Editing your hosts file on a Mac

Step 1:
Open your Mac’s Terminal (by the way, if you’re into trying something new I suggest iTerm2)

Step 2:
Edit your hosts file. It’s located at /private/etc/hosts

In your Terminal window enter the command below

sudo nano /private/etc/hosts

to edit your hosts file you need to enter the command sudo nano /private/etc/hosts

I like to use iTerm2 instead of standard Terminal app

sudo lets you act as the root user, so you’ll be asked to enter root account’s password. Next, nano is a text editor working in your Terminal window, that’s the program we use to edit our hosts file.

Step 3:
Add the following line to the end of the file (also modify according to your likes)

192.168.33.10 mijimo.local www.mijimo.com

The content of hosts file may change from one mac to another

NOTE: Your hosts file may look different than mine

This tells your Mac to directly go to the given IP address without hesitation, when you enter the URL http://mijimo.local or http://www.mijimo.local

Step 4:
Press Control-x, you’ll be prompted to save the changes and exit.

Step 5:
In some cases, you may need to flush your Mac’s DNS cache.

To accomplish this you need to enter the code below:

sudo dscacheutil -flushcache

hosts file directly takes us to our local dev environment

When I enter the address I’m directly taken to my local development environment, which is Scotch box.

And you’re good to go.