If you get error below while trying to installing elasticsearch in Mac OS, you can apply the solution below.


Error


$ 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.

Solution


$ brew tap caskroom/cask
$ brew install brew-cask
$ brew cask install java

$ brew update
$ brew install elasticsearch
$ brew info elasticsearch

Result


$ brew info elasticsearch
elasticsearch: stable 2.2.0, HEAD
Distributed search & analytics engine
https://www.elastic.co/products/elasticsearch
/usr/local/Cellar/elasticsearch/2.2.0_1 (57 files, 31.3M) *
Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/elasticsearch.rb
==> Caveats
Data: /usr/local/var/elasticsearch/elasticsearch_inanzzz/
Logs: /usr/local/var/log/elasticsearch/elasticsearch_inanzzz.log
Plugins: /usr/local/Cellar/elasticsearch/2.2.0_1/libexec/plugins/
Config: /usr/local/etc/elasticsearch/
plugin script: /usr/local/Cellar/elasticsearch/2.2.0_1/libexec/bin/plugin

To have launchd start elasticsearch at login:
ln -sfv /usr/local/opt/elasticsearch/*.plist ~/Library/LaunchAgents
Then to load elasticsearch now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
Or, if you don't want/need launchctl, you can just run:
elasticsearch