# Install Elasticsearch on Linux
by Seth Kenlon

Following along with Lauren Maffeo's article on how to [Install Elasticsearch on macOS](LINK TO LAURENS ARTICLE), I set about installing Elasticsearch on Linux. The process is very different, but is outlined in detail on the [Elasticsearch website](https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html). However, the official instructions have a lot of detail that isn't necessary if you intend to follow along with Lauren's series as I do, so this article takes a simplified view at installing Elasticsearch on Linux.

## Add the Elasticsearch repository

First, add the Elasticsearch software repository to your system so you can install it and receive updates as needed.

On an RPM-based system, such as Fedora, CentOS, RHEL, or OpenSUSE, create a repository description file in **/etc/yum.repos.d/** called **elasticsearch.repo**:

```
$ cat << EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
```

On Ubuntu or Debian:

```
$ echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
```

Do not use the **add-apt-repository** utility. It causes errors due to a mismatch in its defaults and what Elasticsearch's repository provides. 

This repository contains only the open source features, under the Apache License, of Elasticsearch, with no extra features provided by a subscription. If you need subscription-only features, the **baseurl** must be set to **baseurl=https://artifacts.elastic.co/packages/7.x/yum**, but these features are *not* open source.


## Install

The name of the package you need to install depends on whether you use the open source version or the subscription version. This article uses the open source version, which appends **-oss** to the end of the package name. Without **-oss** appended to the package name, you are requesting the subscription-only version. If you create a repository pointing to the subscription version but try to install the open source version, you will get a fairly non-specific error in return. If you create a repository for the open source version and fail to append **-oss** to the package name, you will get an error. 

Install Elasticsearch with your package manager. For instance, on Fedora, CentOS, or RHEL:

```
$ sudo dnf install elasticsearch-oss
```

On Ubuntu or Debian:

```
$ sudo apt install elasticsearch-oss
```


## Start and enable

Once Elasticsearch has been installed, you must start and enable it:

```
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now elasticsearch.service
```

## Confirm

To confirm that Elasticsearch is running on its default port of 9200, point a web browser to **localhost:9200**. You can use a GUI browser or you can do it in the terminal:

```
$ curl localhost:9200
{

  "name" : "fedora30",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "OqSbb16NQB2M0ysynnX1hA",
  "version" : {
    "number" : "7.2.0",
    "build_flavor" : "oss",
    "build_type" : "rpm",
    "build_hash" : "508c38a",
    "build_date" : "2019-06-20T15:54:18.811730Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
```

## Install Kibana

Kibana is a graphical interface for Elasticsearch. It's included in the Elasticsearch repository, so you can install it with your package manager. As with Elasticsearch itself, you must append **-oss** to the end of the package name if you are using the open source version and not the subscription version:

```
$ sudo dnf install kibana-oss
```

On Ubuntu or Debian:

```
$ sudo apt install kibana-oss
```

Kibana runs on port 5601, so launch a graphical web browser and navigate to **localhost:5601** to start using the Kibana interface.

![Kibana running in Firefox](kibana.jpg)

## Troubleshooting

If you get errors while installing Elasticsearch (such as missing **mvn**, for instance) then you may attempting to install the wrong package. If you are using the open source package, as this article does, then the **baseurl** line in your repository definition must be **baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum** and the names of both the Elasticsearch and Kibana packages must end in **-oss**.

You can also try installing a Java environment manually:

```
$ sudo dnf install java-openjdk-devel java-openjdk
```

If all else fails, try installing the Elasticsearch RPM directly from the Elasticsearch servers:

```
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-7.2.0-x86_64.rpm{,.sha512}
$ shasum -a 512 -c elasticsearch-oss-7.2.0-x86_64.rpm.sha512 && sudo rpm --install elasticsearch-oss-7.2.0-x86_64.rpm
```

If you cannot access either Elasticsearch or Kibana with a web browser, then your firewall may be blocking those ports. You can allow traffic on those ports by adjusting your firewall settings. For instance, if you are running **firewalld** (the default on Fedora and RHEL, and installable on Debian and Ubuntu), then you can use **firewall-cmd**:

```
$ sudo firewall-cmd --add-port=9200/tcp --permanent
$ sudo firewall-cmd --add-port=5601/tcp --permanent
$ sudo firewall-cmd --reload
```

## Explore

You're now set to follow along with Lauren Maffeo's Elasticsearch articles. Follow along and learn!