Skip to content

Instantly share code, notes, and snippets.

@todgru
Created February 9, 2023 23:52
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save todgru/0ba097d63318313f12a52594217f8e2b to your computer and use it in GitHub Desktop.
Save todgru/0ba097d63318313f12a52594217f8e2b to your computer and use it in GitHub Desktop.
Install Elasticsearch 7.x on Apple Macbook Pro M1 Ventura 13.2

Elasticsearch Setup Apple MacBook Pro M1

Apple MacBook Pro M1, 32 GB, Ventura 13.2

Documentation based on comments in this Github Elasticsearch issue.

Install Homebrew

Install Homebrew if not yet installed.

Verify Homebrew is a recent version:

$ brew --version
Homebrew 3.6.21
Homebrew/homebrew-core (git revision c26f1c8714c; last commit 2023-02-08)
Homebrew/homebrew-cask (git revision b69d2bf867; last commit 2023-02-08)

Install Elasticsearch and OpenJDK

brew tap elastic/tap
brew install elastic/tap/elasticsearch-full
brew install openjdk

Symlink OpenJDK so the system Java wrappers can find it. This information is also displayed as a Homebrew “caveat” after installing OpenJDK.

sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Modify Elasticsearch .plist to use the OpenJDK

Edit Elasticsearch homebrew.mxcl.elasticsearch-full.plist to use the OpenJDK:

code /opt/homebrew/Cellar/elasticsearch-full/7.17.4/homebrew.mxcl.elasticsearch-full.plist

Find the full path to OpenJDK:

/usr/libexec/java_home

Insert the following before the last closing </dict>:

    <key>EnvironmentVariables</key>
    <dict>
      <key>ES_JAVA_HOME</key>
      <string>insert the full path from /usr/libexec/java_home here</string>
    </dict>

The entire homebrew.mxcl.elasticsearch-full.plist should look like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>homebrew.mxcl.elasticsearch-full</string>
    <key>ProgramArguments</key>
    <array>
      <string>/opt/homebrew/opt/elasticsearch-full/bin/elasticsearch</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>WorkingDirectory</key>
    <string>/opt/homebrew/var</string>
    <key>StandardErrorPath</key>
    <string>/opt/homebrew/var/log/elasticsearch.log</string>
    <key>StandardOutPath</key>
    <string>/opt/homebrew/var/log/elasticsearch.log</string>
    <key>EnvironmentVariables</key>
    <dict>
      <key>ES_JAVA_HOME</key>
      <string>/opt/homebrew/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home</string>
    </dict>
  </dict>
</plist>

Modify Elasticsearch YML

echo "\nxpack.ml.enabled: false\n" >> /opt/homebrew/etc/elasticsearch/elasticsearch.yml

Set ES_JAVA_HOME

Add the ES_JAVA_HOME environment variable by setting to ~/.zshrc:

echo "\nexport ES_JAVA_HOME=$(/usr/libexec/java_home)\n" >> ~/.zshrc

Run and Test Elasticsearch

In a new shell, launch Elasticsearch:

elasticsearch

In a new shell, curl the local Elasticsearch URL:

$ curl -s http://localhost:9200

Example output:

{
  "name" : "my-machine",
  "cluster_name" : "elasticsearch_foo_bar",
  "cluster_uuid" : "some-uuid",
  "version" : {
    "number" : "7.17.4",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "build-hash",
    "build_date" : "2022-05-18T18:04:20.964345128Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
@avinash-ganta
Copy link

Thank you so much!

@minhnguyennhatdev
Copy link

thank you sir

@nirjhareswar
Copy link

Thank you so much! Saved a lot of time.

@gabrieImoreira
Copy link

Thank you so much! I have researched a lot about this installation and I found nothing about it and you saved me!

@chrishough
Copy link

This is no longer working...

The latest openjdk is 20.0.1

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>homebrew.mxcl.elasticsearch-full</string>
    <key>ProgramArguments</key>
    <array>
      <string>/opt/homebrew/opt/elasticsearch-full/bin/elasticsearch</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>WorkingDirectory</key>
    <string>/opt/homebrew/var</string>
    <key>StandardErrorPath</key>
    <string>/opt/homebrew/var/log/elasticsearch.log</string>
    <key>StandardOutPath</key>
    <string>/opt/homebrew/var/log/elasticsearch.log</string>
    <key>EnvironmentVariables</key>
    <dict>
      <key>ES_JAVA_HOME</key>
      <string>/opt/homebrew/Cellar/openjdk/20.0.1/libexec/openjdk.jdk/Contents/Home</string>
    </dict>
  </dict>
</plist>

The elasticsearch command appears to work but brew services fails..

Name               Status     User             File
elasticsearch-full error  256 christopherhough ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch-full.plist
postgresql@14      started    christopherhough ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist
redis              started    christopherhough ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
➜  ~ brew services start elasticsearch-full
Warning: Calling plist_options is deprecated! Use service.require_root instead.
Please report this issue to the elastic/tap tap (not Homebrew/brew or Homebrew/homebrew-core), or even better, submit a PR to fix it:
  /opt/homebrew/Library/Taps/elastic/homebrew-tap/Formula/elasticsearch-full.rb:68

Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/christopherhough/Library/LaunchAgents/homebrew.mxcl.elasticsearch-full.plist` exited with 5.
➜  ~```

@LucasArruda
Copy link

LucasArruda commented May 16, 2023

@chrishough someone suggested here https://stackoverflow.com/a/68992328 to restart and it worked for me.

But there might be a caveat. I also installed OpenJDK 17, not 20. It might be just the restart command, since I could not straight start with 17 and also had to do a restart: brew services restart elastic/tap/elasticsearch-full.

But here it goes.

I installed OpenJDK17.

brew remove openjdk
brew install openjdk@17
sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Changed ~/.zshrc to:

# OpenJDK fix for Java/ElasticSearch in Mac OS Ventura
export ES_JAVA_HOME=/opt/homebrew/Cellar/openjdk@17/17.0.7/libexec/openjdk.jdk/Contents/Home

Changed the path in /opt/homebrew/Cellar/elasticsearch-full/7.17.4/homebrew.mxcl.elasticsearch-full.plist to JDK 17.

    <key>EnvironmentVariables</key>
    <dict>
      <key>ES_JAVA_HOME</key>
      <string>/opt/homebrew/Cellar/openjdk@17/17.0.7/libexec/openjdk.jdk/Contents/Home</string>
    </dict>

I closed and re-opened terminal just for the eval (opened a new tab, actually hehehe)

The start failed, but this worked:

brew services restart elastic/tap/elasticsearch-full.

@rdsngit
Copy link

rdsngit commented Jun 2, 2023

Thank you! This worked on my M1 Mac running MacOS Ventura 13.4.

After following these instructions I had to also run brew services restart elasticsearch-full

@shane-syc
Copy link

Thank you!!!

@mvargas33
Copy link

Thanks a lot!!

@Jukebox7
Copy link

Jukebox7 commented Jul 3, 2023

Thank you for this setup 🙏

For those who have a M2 and find this doc for M1

Maybe as me you saw than doing this setup, you don't have anything in your /opt/ directory. And this will definitively affect this setup because of the ln -sfn command or just the env variable of your shell.

Don't worry, you just need to find the new path of openjdk for me it's /usr/local/Cellar/openjdk, inside you will find the /Contents/Home, and with that last directory you will have your ES_JAVA_HOME env variable.

Just read the again the original setup keeping in mind that /opt/homebrew is now replaced by /usr/local and it will roll like clockwork 👌

@ajithlalrg
Copy link

When I tired with brew install elastic/tap/elasticsearch-full
The below error is coming up kindly help on this issue

Error: elastic/tap/elasticsearch-full: Calling plist_options is disabled! Use service.require_root instead.
Please report this issue to the elastic/tap tap (not Homebrew/brew or Homebrew/homebrew-core), or even better, submit a PR to fix it:
  /opt/homebrew/Library/Taps/elastic/homebrew-tap/Formula/elasticsearch-full.rb:68

@PikachuEXE
Copy link

@vieanhng
Copy link

vieanhng commented Aug 9, 2023

thank you

@NearXdu
Copy link

NearXdu commented Sep 22, 2023

thanks it's worked for me

@arrrrny
Copy link

arrrrny commented Oct 19, 2023

For those who have issues starting as a service, here is the solution.
elastic/homebrew-tap#161 (comment)

@rahulseetharaman
Copy link

Worked smooth as butter ! Thank you so much !

@temberature
Copy link

Install elasticsearch with Homebrew on OSX Ventura · Issue #91159 · elastic/elasticsearch
elastic/elasticsearch#91159

@dav1dian
Copy link

dav1dian commented Jan 27, 2024

Thank you for this post! it works.
But I have an issue with installing The Phonetic Analysis plugin
when I'm trying to do - sudo bin/elasticsearch-plugin install elasticsearch/elasticsearch-analysis-phonetic i have this error pretty much similar to what i had when tried to start elasticsearch
popup with - “jdk” is damaged and can’t be opened. You should move it to the Bin.
and also error in command line
/opt/homebrew/Cellar/elasticsearch-full/7.17.4/libexec/bin/elasticsearch-env: line 83: 27986 Killed: 9 "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.java_version_checker.JavaVersionChecker
Could you please help to fix this?

@DimaHendawi
Copy link

Work! thank you so much.

what about this issue?
brew install elastic/tap/kibana-full

Error: elastic/tap/kibana-full: undefined method plist_options' for Formulary::FormulaNamespace8c5a25144e1fd171ea16b03c911e774f470311d917e11f85bae3724bebb79a29::KibanaFull:Class`

@kuehn-sba
Copy link

kuehn-sba commented Mar 28, 2024

note, echo requires the -e option to enable the interpretation of backslash escapes:
echo -e "\nxpack.ml.enabled: false\n" >> /opt/homebrew/etc/elasticsearch/elasticsearch.yml

..and get sure /usr/libexec/java_home is pointing to your installed JDK, otherwise you can set this directly for ES_JAVA_HOME

@avinashv37
Copy link

avinashv37 commented Apr 7, 2024

Thank you ! this worked in M3 pro, but the same steps did not work for Kibana by editing the homebrew.mxcl.kibana-full.plist , any solution for Kibana ?

@gMerm
Copy link

gMerm commented Apr 17, 2024

Thank you so much, it worked perfectly for macbook M1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment