How to open google chrome from terminal?

Spencer Rohan picture Spencer Rohan · Jan 14, 2016 · Viewed 95.7k times · Source

I'm trying to create an alias that opens google chrome to localhost. Port 80 in this case.

I'd also really like to be able to be in any git directory and have it open that specific project in the browser, but I'm not sure if that's even possible.

  • How do I open google chrome from the terminal?
  • What alias could I use to open the current git project in the browser?

More Details:

  1. My localhost is set to port 80.
  2. I store my git repositories in ~/Sites/ - meaning if I wanted to view any project in the browser it would be found here: http://localhost/FILENAME

Thank You

Answer

John picture John · Jan 31, 2017

From the macOS Terminal, use open with the -a flag and give the name of the app you want to open. In this case "Google Chrome". You may pass it a file or URL you want it to open with.

open -a "Google Chrome" index.html