# How to compile filebeat source code?

**URL:** <https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158>\
**Category:** Beats\
**Tags:** beats-development\
**Created:** [March 27, 2019, 3:12pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158 "2019-03-27T15:12:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortezaipo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortezaipo/32/43159_2.png) [@mortezaipo](https://discuss.elastic.co/u/mortezaipo)\
**Post date:** [March 27, 2019, 3:12pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/1 "2019-03-27T15:12:32Z")

</div>

Hi,  
I've developed my own 'output' and I've introduced it to the publisher.  
Now I have a problem that I want to compile it and use it in a production mode.  
I've checked the 'developer' doc and I didn't find anything for it except `make testsuite` which setups too many Docker images.

So, how can I use Filebeat in production mode by compiling the source code completely?

Cheers,  
Morteza

---

<div class="post-metadata">

**Author:** ![kvch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvch/32/72058_2.png) [@kvch](https://discuss.elastic.co/u/kvch)\
**Post date:** [March 27, 2019, 3:22pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/2 "2019-03-27T15:22:01Z")

</div>

You can compile Filebeat by running `mage build` in the root of the beat. It creates a Filebeat binary for you.

What do you mean by production mode?

---

<div class="post-metadata">

**Author:** ![mortezaipo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortezaipo/32/43159_2.png) [@mortezaipo](https://discuss.elastic.co/u/mortezaipo)\
**Post date:** [March 27, 2019, 3:26pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/3 "2019-03-27T15:26:34Z")

</div>

Thank you.  
Well I've changed some parts of the code and I want to build and run it on the server. By production I mean that all parts work well for production and not just for development.

I've tried `mage build` but it shows this error: `Unknown target specified: build`

---

<div class="post-metadata">

**Author:** ![mortezaipo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortezaipo/32/43159_2.png) [@mortezaipo](https://discuss.elastic.co/u/mortezaipo)\
**Post date:** [March 27, 2019, 5:03pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/4 "2019-03-27T17:03:29Z")

</div>

it compiles `libbeat` file by this action:

```auto
cd elastic/beats/libbeat
mage -l
mage build

```

It only says:

```auto
{
  "@timestamp": "2019-03-27T16:43:50.725Z",
  "@metadata": {
    "beat": "mockbeat",
    "type": "doc",
    "version": "9.9.9"
  },
  "host": {
    "name": "myhost"
  },
  "message": "Mockbeat is alive!",
  "type": "mock",
  "beat": {
    "name": "myhost",
    "hostname": "myhost",
    "version": "9.9.9"
  }
}

```

It seems to be mock. So it seems that I did something wrong because it's not the production binary file.

Also it never supports 'output' like `console`: `console output doesn't support testing`.

Sample yml config file:

```auto
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - test.log

output.console:
  pretty: true

```

---

<div class="post-metadata">

**Author:** ![kvch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvch/32/72058_2.png) [@kvch](https://discuss.elastic.co/u/kvch)\
**Post date:** [March 28, 2019, 8:16am UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/5 "2019-03-28T08:16:00Z")

</div>

You need to run it in the root of the beat. In this case filebeat.

Do you want to package it yourself to install it on you server?

---

<div class="post-metadata">

**Author:** ![mortezaipo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortezaipo/32/43159_2.png) [@mortezaipo](https://discuss.elastic.co/u/mortezaipo)\
**Post date:** [March 28, 2019, 12:51pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/6 "2019-03-28T12:51:11Z")

</div>

By this action I've compiled and run it successfully:

```auto
$ cd ~/.go/src/github.com/elastic/beats/filebeat/
$ mage build
$ ./filebeat -e

```

and works fine.

> [@kvch](#):
>
> Do you want to package it yourself to install it on you server?

Yes exactly. Would you please guide me how can package it by myself?

---

<div class="post-metadata">

**Author:** ![kvch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvch/32/72058_2.png) [@kvch](https://discuss.elastic.co/u/kvch)\
**Post date:** [March 29, 2019, 11:47am UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/7 "2019-03-29T11:47:50Z")

</div>

You can run `make snapshot` which creates a snapshot of the current codebase under `build/distributions`. To control which platform to build for set `PLATFORMS`.

To build packages for `linux/amd64` you need to run the following command:

```auto
PLATFORMS=linux/amd64 make snapshot

```

This creates a DEB, an RPM and a tar.gz release.

---

<div class="post-metadata">

**Author:** ![mortezaipo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortezaipo/32/43159_2.png) [@mortezaipo](https://discuss.elastic.co/u/mortezaipo)\
**Post date:** [March 29, 2019, 1:10pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/8 "2019-03-29T13:10:37Z")

</div>

Thank you so much.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 26, 2019, 1:10pm UTC](https://discuss.elastic.co/t/how-to-compile-filebeat-source-code/174158/9 "2019-04-26T13:10:38Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
