# Automatically start browser on localhost:4000 after \`jekyll serve\`

**URL:** <https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916>\
**Category:** Help\
**Created:** [August 29, 2020, 3:52pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916 "2020-08-29T15:52:35Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [August 29, 2020, 3:52pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/1 "2020-08-29T15:52:35Z")

</div>

Dear colleagues:

I’m starting to use `make` to steer my jekyll work, and find it saves much typing. One specific target is `make serve`. There after `bundle exec jekyll serve --livereload` I want to start the browser on port 4000 when the building is done. So far I do the following:

> serve s:
> 
> > (sleep 5; open “[http://localhost:4000/index.html](http://localhost:4000/index.html)”) &  
> > bundle exec jekyll serve --livereload

This allows jekyll to build and enter serve mode, while in the background the browser is started after 5 s. This is not fully satisfactory since the 5 seconds are frequently not enough.  
Better ideas?

PS: For those (like me!) to very fluent in shell speak: the parentheses form a “command group”, allowing the 2-command sequence to be converted to a background job via the ampersand symbol.

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [August 29, 2020, 4:55pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/2 "2020-08-29T16:55:14Z")

</div>

Recent versions of Jekyll have the `-o`/`--open-url` option [_corrected dashes_] that will automatically open a browser window once the site is running.

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [August 29, 2020, 6:10pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/3 "2020-08-29T18:10:49Z")

</div>

> [@chuckhoupt](#):
>
> `-open-url`

Thank you! Great! (Double dash, BTW). Now my make command reads

> bundle exec jekyll serve --livereload --open-url [http://localhost:4000/](http://localhost:4000/)

Totally solves my problem. I’m sure this option will soon enter the documentation.

Thanks, best, Michael

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [August 29, 2020, 8:49pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/4 "2020-08-29T20:49:49Z")

</div>

Ah, you’re right, the option isn’t documented on the site. It does appear in the command-line help (`jekyll help serve`). I’ve sent in a [pull-request to fix the site](https://github.com/jekyll/jekyll/pull/8365).

The `--open-url` option doesn’t take an argument, so the `http://localhost:4000/` is unnecessary. To set the host and port, there are `--host`/`--port` options. For example, to serve the site on the local net from the computer named “Eddy” on port 8080:

```nohighlight
bundle exec jekyll serve --livereload --open-url --host eddy.local --port 8080
# Browser opens to http://eddy.local:8080

```

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [August 29, 2020, 9:29pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/5 "2020-08-29T21:29:33Z")

</div>

Thank you again! I was not aware that `jekyll -h` could be augmented with a subcommand! Now I see the many options, also for the other subcommands. And I’ve left off the URL.  
Interesting: while `--livereload` can be placed into \_config.yml as `livereload: true`, this does not seem to be the case for `--open-url`.

This great community is a major asset of jekyll!

Best, Michael

---

<div class="post-metadata">

**Author:** ![brad](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/brad/32/2543_2.png) [@brad](https://talk.jekyllrb.com/u/brad)\
**Post date:** [August 29, 2020, 9:55pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/6 "2020-08-29T21:55:57Z")

</div>

I like to use Firefox Developer edition when I’m building stuff but the regular edition when I’m just surfing. I’ve installed the npm package [parallelshell](https://www.npmjs.com/package/parallelshell) globally and have an alias defined with `parallelshell "bundle exec jekyll serve --livereload" "~/.local/share/firefox_dev/firefox 'http://localhost:4000/'"`

The only thing to know with this is when you kill the server with Ctrl+C, it closes the browser.

---

<div class="post-metadata">

**Author:** ![angeliquejw](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/angeliquejw/32/2749_2.png) [@angeliquejw](https://talk.jekyllrb.com/u/angeliquejw)\
**Post date:** [August 30, 2020, 2:52pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/7 "2020-08-30T14:52:21Z")

</div>

Whelp, that’s awesome and simple. Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [August 30, 2020, 3:46pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/8 "2020-08-30T15:46:13Z")

</div>

Again a juseful pearl. Thank you!

---

<div class="post-metadata">

**Author:** ![roadiereloaded](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/roadiereloaded/32/2431_2.png) [@roadiereloaded](https://talk.jekyllrb.com/u/roadiereloaded)\
**Post date:** [August 31, 2020, 7:32am UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/9 "2020-08-31T07:32:08Z")

</div>

thank you for posting this. Works great. I now use  
`alias jekyllserver="jekyll serve --host 0.0.0.0 --open-url"`  
and this leaves the tab open in safari when I stop the jekyll serve command. reload is done by watch.rb script.

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [August 31, 2020, 8:01am UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/10 "2020-08-31T08:01:27Z")

</div>

Great. Yet, as we learned from [chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt), the argument `http://localhost:4000/`is not necessary.

---

<div class="post-metadata">

**Author:** ![roadiereloaded](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/roadiereloaded/32/2431_2.png) [@roadiereloaded](https://talk.jekyllrb.com/u/roadiereloaded)\
**Post date:** [August 31, 2020, 8:36am UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/11 "2020-08-31T08:36:07Z")

</div>

excellent - edited the alias. works as advertised. thanks

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [August 31, 2020, 9:16pm UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/12 "2020-08-31T21:16:29Z")

</div>

Another approach is that will ctrl click on the URL in the console after start and that will open in the browser

If your terminal or IDE terminal supports links

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [September 5, 2020, 1:13am UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/13 "2020-09-05T01:13:14Z")

</div>

> [@michaelbach](#):
>
> I’m sure this option will soon enter the documentation.

The pull request landed, so now the Open-URL option and flag are documented (along with several other missing build and serve flags):

> **[Configuration Options](https://jekyllrb.com/docs/configuration/options/)**
>
> The tables below list the available settings for Jekyll, and the various options (specified in the configuration file) and flags (specified on the command-line) that control them.

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [September 5, 2020, 7:04am UTC](https://talk.jekyllrb.com/t/automatically-start-browser-on-localhost-4000-after-jekyll-serve/4916/14 "2020-09-05T07:04:28Z")

</div>

great! Found even more new useful options. Thanks.
