How to open google chrome from terminal?
Solution 1
UPDATE:
- 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.
- 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 2
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 3
On Linux, just use this command in a terminal:
google-chrome
Solution 4
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 linealias 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 5
just type
google-chrome
it works. Thanks.
Comments
-
Spencer Rohan almost 2 years
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:
- My localhost is set to port 80.
- 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
-
Ulysse BN over 5 yearsbash has a
~/.bashrc
as well. I would not recommend aliases in~/.profile
, that is more about env variable. -
mklement0 almost 5 yearsWorth noting that, unlike
xdg-open
(oropen
on macOS) for using the default browser,google-chrome
runs synchronously, i.e., blocks the calling shell until the newly opened tab is closed; appending&
makes it asynchronous. -
Íhor Mé over 4 yearsIn what scenario did it run in sync? I wasn't able to reproduce the sync behaviour you talked about, @mklement0 , always works async to me, never waits for tab to close.
-
mklement0 over 4 years@ÍhorMé: Google Chrome 76.0.3809.87 on Ubuntu 18.04.2 LTS.
-
Íhor Mé over 4 yearsI'm also on that. Actually, now I find I do get this exp with
google-chrome http://example --no-sandbox
. And when I run without --no-sandbox I don't, but I can't run without that one under root. Throws[32610:32610:0815/130649.955364:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
-
skillit zimberg over 4 yearsI just added
alias chrome="open -a 'Google Chrome'"
to my.zshrc
file. Thank you! -
Ariel Mirra about 4 yearsdoes not work in macOS Catalina. However just using open <URL> works if chrome is your default browser.
-
Y. Joy Ch. Singha about 4 yearsactually, i do work in ubuntu, and its working fine. But am not sure in macOS.
-
Muhammad Umer about 3 yearshow do you pass flags
-
ricardorover about 2 yearsIf someone else wants to use it inside a Makefile on linux, it worked for me when I used
xdg-open
. Found the tip here stackoverflow.com/a/35811643/1594227