# Install from Source

This article explains how to install Fluentd from source (git repository). This is useful for developers.

## Step 1: Install Ruby Interpreter

Install Ruby `>= 2.7` and `bundler` on your local environment.

## Step 2: Fetch Source Code

Fetch the source code from GitHub. The official repository is located [here](http://github.com/fluent/fluentd/).

```
$ git clone https://github.com/fluent/fluentd.git
$ cd fluentd
```

The `master` branch is now for `v1` development.

## Step 3: Build and Install

Build the package with `rake` and install it with `gem`:

```
$ bundle install
Fetching gem metadata from https://rubygems.org/.........
...
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ bundle exec rake build
fluentd xxx built to pkg/fluentd-xxx.gem.
$ gem install pkg/fluentd-xxx.gem
```

## Step 4: Run

Run the following commands to verify the Fluentd installation:

```
$ fluentd --setup ./fluent
$ fluentd -c ./fluent/fluent.conf -vv &
$ echo '{"json":"message"}' | fluent-cat debug.test
```

The second command starts Fluentd as a daemon. If you want to stop its daemon, you can use `$ pkill -f fluentd`. The last command sends Fluentd a message '{"json":"message"}' with a `debug.test` tag. If the installation is successful, Fluentd will output the following message:

```
2011-07-10 16:49:50 +0900 debug.test: {"json":"message"}
```

It is highly recommended to set up `ntpd` on the node to prevent invalid timestamps in your logs.

For large deployments, you must use [`jemalloc`](http://www.canonware.com/jemalloc/) to avoid memory fragmentation. This is already included in the [`rpm`](https://docs.fluentd.org/installation/install-fluent-package/install-by-rpm-fluent-package) and [`deb`](https://docs.fluentd.org/installation/install-fluent-package/install-by-deb-fluent-package) packages.

## Troubleshooting

### Cannot install on M1 macOS

There is a known problem in the system Ruby on M1 macOS that `fluentd --setup ./fluent` command in Step.4 fails with an error similar to the following.

```
.../kernel_require.rb:XX:in `require': dlopen(...):
missing compatible arch in ... (LoadError)
```

The system Ruby on macOS, which is like `universal.XXX-darwinXX` (you can check it by `$ ruby -v`) may cause this error. If you use the system Ruby, this error can be resolved by reinstalling Ruby.

As an example, you can reinstall Ruby by using [Homebrew](https://brew.sh/).

```
$ brew reinstall --build-from-source ruby
```

## Next Steps

You are now ready to collect real logs with Fluentd. Refer to the following tutorials on how to collect data from various sources:

* Basic Configuration
  * [Config File](https://docs.fluentd.org/configuration/config-file)
* Application Logs
  * [Ruby](https://docs.fluentd.org/language-bindings/ruby), [Java](https://docs.fluentd.org/language-bindings/java), [Python](https://docs.fluentd.org/language-bindings/python), [PHP](https://docs.fluentd.org/language-bindings/php),

    [Perl](https://docs.fluentd.org/language-bindings/perl), [Node.js](https://docs.fluentd.org/language-bindings/nodejs), [Scala](https://docs.fluentd.org/language-bindings/scala)
* Examples
  * [Store Apache Log into Amazon S3](https://docs.fluentd.org/how-to-guides/apache-to-s3)
  * [Store Apache Log into MongoDB](https://docs.fluentd.org/how-to-guides/apache-to-mongodb)
  * [Data Collection into HDFS](https://docs.fluentd.org/how-to-guides/http-to-hdfs)

If this article is incorrect or outdated, or omits critical information, please [let us know](https://github.com/fluent/fluentd-docs-gitbook/issues?state=open). [Fluentd](http://www.fluentd.org/) is an open-source project under [Cloud Native Computing Foundation (CNCF)](https://cncf.io/). All components are available under the Apache 2 License.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fluentd.org/installation/install-from-source.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
