brew install elasticsearch on M1 macbook results in "Bad CPU type in executable" error
Asked Answered
A

3

7

I have a fresh Macbook Air with M1 processor

Following official guide https://www.elastic.co/guide/en/elasticsearch/reference/current/brew.html I've tried to install elasticsearch 7 with:

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

once I try to start it with $ elasticsearch I get this error:

/opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/bin/elasticsearch-env: line 83: /opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/jdk.app/Contents/Home/bin/java: Bad CPU type in executable

If I try to start the service with brew services start elastic/tap/elasticsearch-full It will fails and I'll get same error in log file /opt/homebrew/var/log/elasticsearch.log

/opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/bin/elasticsearch-env: line 83: /opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/jdk.app/Contents/Home/bin/java: Bad CPU type in executable

Once I open the file (elasticsearch-env) that causes the issue line 83 reads:

# check the Java version
"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.java_version_checker.JavaVersionChecker

If I try to execute

/opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/jdk.app/Contents/Home/bin/java

I get the error

 Bad CPU type in executable

So it seems a bad Java architecture was installed during the elasticsearch-full brew instalation (maybe instead of M1 it's x84 or something ?). This is fresh new Macbook bought couple of hours ago. Elasticsearch was first thing I've tried to brew install on it (so no prior Java application installed)

Anyone knows how to solve this pretty please ?

Aciniform answered 22/12, 2021 at 21:47 Comment(0)
A
2

Ok the issue was that I needed to install the Java JDK separately.

I've just installed Java OSX ARM DMG and then ES was working

As long as $ java -version don't throw you an error this error will not appear

Aciniform answered 23/12, 2021 at 9:16 Comment(0)
D
10

You can also fix this by installing Rosetta 2 on your ARM Mac: softwareupdate --install-rosetta.

Apparently brew still installs the 64 bit version of elasticsearch.

Daemon answered 26/1, 2022 at 13:7 Comment(0)
A
2

Ok the issue was that I needed to install the Java JDK separately.

I've just installed Java OSX ARM DMG and then ES was working

As long as $ java -version don't throw you an error this error will not appear

Aciniform answered 23/12, 2021 at 9:16 Comment(0)
P
-1

These instructions helped me to solve this issue on my M1.

Try to install openjdk:

brew install openjdk

and modify Elasticsearch .plist to use the OpenJDK. You must add

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

before the last closing </dict> at homebrew.mxcl.elasticsearch-full.plist file.

Potsherd answered 3/7 at 21:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.