ElasticSearch Setup Using Homebrew

Felix Gondwe
3 min readDec 6, 2017

--

I have found myself doing this over and over and decided to document it to help a soul out there in a similar situation or just looking to get this done quick. Thinking of writing a bash script to automate this but before I do that, let’s take a selfie? No let’s get started 😃

Disclaimer, running this on MacOS. Will do a windows one hopefully soon 😜

Prerequisites

  1. Homebrew Mac package manager
  2. Java, at least version 7

A. Installing homebrew

If you have this already skip this step. Otherwise run the following in your terminal to install homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

B. Install homebrew cask(optional)

This is optional, but will save you lost of time in future. Cask is a brew extension that can install things like java, chrome etc via the terminal. To install cask run the following. Nice thing about brew is it plays with others nicely, it won’t mess up your environment I promise.

brew tap caskroom/cask

C. Install Java

If you didn’t install cask, no worries. Install download and install manually from here.

Run the following in your terminal if you have cask. Make sure to add JAVA to your bash_profile. To avoid hustle of setting the JAVA_HOME variable, please try step D(recommended but optional) after installing java in this current step.

brew cask install java

To Add JAVA to the bash_profile run the following. Check first if it exists to avoid having duplicates just in case.

echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home' >> ~/.bash_profile

D. Install jenv (optional)

Tired of setting up JAVA_HOME environment variable? Well, this is your lucky day! jenv helps you forget that. Run the following in your terminal

brew install jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile

Always good practice to run ‘source ~/.bash_profile’ , without the quotes, in your terminal when you update the .bash_profile file. It basically restarts the .bash_profile so you can run the updates you made.

With jenv you can add all the JDKs you desire, since jenv manages your java environment. For instance, add jdk you just installed. This is what I installed on my machine as of this writing.

jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

Now that we have java setup let’s go ahead and install Elasticsearch, phewww… that took a while.

Installing Elasticsearch via brew

Run the following to see elasticsearch versions available to install

brew search elasticsearch

I installed 2.4 on my machine but feel free to experiment with versions 5, 2.4 or both. Sky is not even the limit 😉

Run the following to install, say 2.4. Also add it to your PATH if you desire so.

brew install elasticsearch@2.4
echo 'export PATH="/usr/local/opt/elasticsearch@2.4/bin:$PATH"' >> ~/.bash_profile

To run it, run the following

elasticsearch

Or if you want this to run in the background when you start your machine run the following(I do this because am lazy). Nobody got time to run same command over and over 😜

brew services start elasticsearch@2.4

Sanity test, go to: http://localhost:9200

ElasticSearch plugins: Monitoring Elasticsearch

Before we go, let’s try to setup one of my favorite plugins for version 2.4 called kopf.

if you installed elasticsearch via homebrew, you can install plugins via the following path on your machine.

/usr/local/cellar/elasticsearch@2.4/2.4.6/libexec/bin/plugin

To install kopf run the following

/usr/local/cellar/elasticsearch@2.4/2.4.6/libexec/bin/plugin install lmenezes/elasticsearch-kopf

Sanity test, go to http://localhost:9200/_plugin/kopf

— — — — — — — — — — — — — — — — — — — — — — — — — —

Summary

  1. Setup homebrew, package manager for mac.
  2. Setup JAVA as it is required to successfully run elasticsearch in your local box or where ever you plan to set it up
  3. Finally install elasticsearch
  4. Install elasticsearch plugins like kopf if you like.

Resources:

https://www.elastic.co/guide/en/elasticsearch/reference/2.4/_installation.html, https://brew.sh/, http://www.jenv.be/, http://davidcai.github.io/blog/posts/install-multiple-jdk-on-mac/,https://github.com/lmenezes/elasticsearch-kopf

— — — — — — — — — — — — — — — — — — — — — — — — — —

You should have elasticsearch all setup now. Watch out for another post on elasticsearch usage or real world application. Feel free to share the love, don’t be shy. Happy indexing 😄

--

--