How to open google chrome from terminal?
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
On Linux, just use this command in a terminal:
google-chrome
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.
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!