Steps to quickly install Elasticsearch on Mac with Homebrew

Tadashi Shigeoka ·  Tue, April 26, 2016

I installed Elasticsearch on macOS, so I’ll introduce the steps.

Elasticsearch | エラスティックサーチ

Check available Elasticsearch versions for installation

It looks like we can install the latest version 2.3.1 as of April 26, 2016.

$ brew info elasticsearch
elasticsearch: stable 2.3.1, HEAD
Distributed search & analytics engine
https://www.elastic.co/products/elasticsearch
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/elasticsearch.rb
==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_sandbox/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_sandbox.log
Plugins: /usr/local/Cellar/elasticsearch/2.3.1/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/Cellar/elasticsearch/2.3.1/libexec/bin/plugin

To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch

Install Elasticsearch

When trying to quickly install elasticsearch with the brew command, an error occurs saying there’s no Java. Java…

$ brew install elasticsearch
elasticsearch: Java 1.7+ is required to install this formula.
You can install with Homebrew Cask:
  brew install Caskroom/cask/java

You can download from:
  http://www.oracle.com/technetwork/java/javase/downloads/index.html
Error: An unsatisfied requirement failed this build.

Install Java

While we could install Java from Oracle’s official site, to make things easy, let’s install Java with the brew command too.

$ brew install Caskroom/cask/java
==> brew cask install Caskroom/cask/java
==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
Password:
==> Caveats
This Cask makes minor modifications to the JRE to prevent issues with
packaged applications, as discussed here:

  https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361

If your Java application still asks for JRE installation, you might need
to reboot or logout/login.

Installing this Cask means you have AGREED to the Oracle Binary Code
License Agreement for Java SE at

  http://www.oracle.com/technetwork/java/javase/terms/license/index.html

==> Downloading http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-macosx-x64.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask java
==> Running installer for java; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
==> installer: Package name is JDK 8 Update 92
==> installer: Installing at base path /
==> installer: The install was successful.
🍺  java staged at '/opt/homebrew-cask/Caskroom/java/1.8.0_92-b14' (2 files, 227M)

Let’s confirm that Java is installed just to be sure.

$ java -version 
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

Install Elasticsearch again

$ brew install elasticsearch
==> Downloading https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.1/elasticsearch-2.3.1.tar.gz
######################################################################## 100.0%
==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_sandbox/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_sandbox.log
Plugins: /usr/local/Cellar/elasticsearch/2.3.1/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/Cellar/elasticsearch/2.3.1/libexec/bin/plugin

To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch
==> Summary
🍺  /usr/local/Cellar/elasticsearch/2.3.1: 59 files, 29.4M, built in 1 minute 40 seconds

Let’s also check the elasticsearch version just to be sure.

$ elasticsearch --version
Version: 2.3.1, Build: bd98092/2016-04-04T12:25:05Z, JVM: 1.8.0_92

Start elasticsearch

Let’s start Elasticsearch.

$ brew services start elasticsearch
==> Tapping homebrew/services
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
Checking connectivity... done.
Tapped 0 formulae (32 files, 46.0K)
==> Successfully started `elasticsearch` (label: homebrew.mxcl.elasticsearch)

I confirmed that the elasticsearch process is running.

$ ps aux | grep elasticsearch
your_username          1308   0.5  1.5  5075616 256028   ??  S     7:04PM   0:07.18 /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/local/Cellar/elasticsearch/2.3.1/libexec -cp /usr/local/Cellar/elasticsearch/2.3.1/libexec/lib/elasticsearch-2.3.1.jar:/usr/local/Cellar/elasticsearch/2.3.1/libexec/lib/* org.elasticsearch.bootstrap.Elasticsearch start
your_username          1327   0.0  0.0  2432772    560 s000  S+    7:04PM   0:00.00 grep --color=always elasticsearch

[Bonus] Install elasticsearch-head

Elasticsearch has a mechanism for installing plugins, and installing elasticsearch-head allows you to check various things from a browser.

$ /usr/local/Cellar/elasticsearch/2.3.1/libexec/bin/plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading 
...............................................................................................DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed head into /usr/local/Cellar/elasticsearch/2.3.1/libexec/plugins/head

The admin interface URL is http://localhost:9200/_plugin/head/.

Since I’m just getting started with Elasticsearch, I want to gradually catch up on it.

That’s all from the Gemba.