How to open google chrome from terminal?

GitBashGoogle ChromeTerminalAlias

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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 

Solution 2 - Git

On Linux, just use this command in a terminal:

google-chrome

Solution 3 - Git

If you just want to open the Google Chrome from terminal instantly for once then open -a "Google Chrome" works fine from Mac Terminal.

If you want to use an alias to call Chrome from terminal then you need to edit the bash profile and add an alias on ~/.bash_profile or ~/.zshrc file.The steps are below :

  • Edit ~/.bash_profile or ~/.zshrc file and add the following line alias chrome="open -a 'Google Chrome'"
  • Save and close the file.
  • Logout and relaunch Terminal
  • Type chrome filename for opening a local file.
  • Type chrome url for opening url.

Solution 4 - Git

UPDATE:

  1. How do I open google chrome from the terminal?

Thank you for the quick response. open http://localhost/ opened that domain in my default browser on my Mac.

  1. What alias could I use to open the current git project in the browser?

I ended up writing this alias, did the trick:

# Opens git file's localhost; ${PWD##*/} is the current directory's name
alias lcl='open "http://localhost/${PWD##*/}/"'

Thank you again!

Solution 5 - Git

just type

google-chrome

it works. Thanks.

Solution 6 - Git

on mac terminal (at least in ZSH): open stackoverflow.com (opens site in new tab in your chrome default browser)

Solution 7 - Git

In Terminal, type open -a Google\ Chrome

This will open Google Chrome application without any need to manipulate directories!

Solution 8 - Git

Use command

google-chrome-stable

We can also use command

google-chrome

To open terminal but in my case when I make an interrupt ctrl + c then it get closed so I would recommend to use google-chrome-stable instead of google-chrome

Solution 9 - Git

For macOS you can use this command:

open -a Google\ Chrome "https://google.com"

Solution 10 - Git

On linux [ubuntu] in terminal, write:

google-chrome 'https://google.com' 2> /dev/null

ending part 2> /dev/null ommits output from command in terminal and allows to type without disturbing comments from that command.

for new-ones in scripting (linux users):
u can also create some nice readable function in ~/.bashrc directory like:

open(){
    google-chrome $1 2> /dev/null
}

and in terminal using it like this:

open htts://google.com

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSpencer RohanView Question on Stackoverflow
Solution 1 - GitJohnView Answer on Stackoverflow
Solution 2 - GitHassan AbbasiView Answer on Stackoverflow
Solution 3 - GittheRanaView Answer on Stackoverflow
Solution 4 - GitSpencer RohanView Answer on Stackoverflow
Solution 5 - GitY. Joy Ch. SinghaView Answer on Stackoverflow
Solution 6 - GitMauiGonzoView Answer on Stackoverflow
Solution 7 - GitDGomonovView Answer on Stackoverflow
Solution 8 - GitAjay kumarView Answer on Stackoverflow
Solution 9 - Gitаlex dykyіView Answer on Stackoverflow
Solution 10 - GitPaweł WitekView Answer on Stackoverflow