77

I'm trying to install Elasticsearch 1.1.0 on OSX Mavericks but i got the following errors when i'm trying to start:

:> ./elasticsearch
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.Version
at org.elasticsearch.bootstrap.Bootstrap.buildErrorMessage(Bootstrap.java:252)
at org.elasticsearch.bootstrap.Bootstrap.main(Bootstrap.java:236)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:32)

Also when i'm executing the same command with -v arg, i got this error:

:> ./elasticsearch -v
Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_36
at org.elasticsearch.Version.<clinit>(Version.java:42)

Here's my environment:

Java version

>: java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

Instalation path (downloaded .tar.gz archive from elasticsearch download page and extracted here):

/usr/local/elasticsearch-1.1.0

ENV vars:

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home 
CLASSPATH=/usr/local/elasticsearch-1.1.0/lib/*.jar:/usr/local/elasticsearch-1.1.0/lib/sigar/*.jar

UPDATE

i finally make it working, unfortunally not sure how because i tried a lot of changes :). But here's a list of changes i made that can help:

~/Library/Caches

/Library/Caches

  • i removed CLASSPATH env var.

  • ES_PATH and ES_HOME env vars are not set either, but i think this is not so important.

Note: now it's working also if i'm installing with brew.

Thanks.

Catalin M.
  • 1,026
  • 1
  • 8
  • 7

6 Answers6

215

You should really consider using brew. It's a great tool that will take care of dependencies, version control and much more.

To install Elasticsearch using brew, simply:

brew update
brew install elasticsearch

Boom! Done.

After that follow Elasticsearch instructions :

  1. To have launchd start Elasticsearch at login:

    ln -sfv /usr/local/opt/elasticsearch/*.plist ~/Library/LaunchAgents
    
  2. 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
    
Pierre-Louis Gottfrois
  • 17,561
  • 8
  • 47
  • 71
  • Thanks, i tried also with brew but same errors received – Catalin M. Apr 04 '14 at 08:54
  • brew installes old version – Maxim Yefremov May 29 '14 at 11:42
  • 2
    It seems that brew can't actually handle this particular dependency : `ElasticSearch requires Java 7; you will need to install an appropriate JDK.` (the more annoying thing is that Oracle installers insist I have Java 8 installed ... nothing else seems to realize it) – Joe Jun 18 '14 at 21:38
  • 2
    works just fine for me. at first displayed error, stating it requires JDK. good thing is it gave me a command that I can copy/paste to download JDK. once that's done, I install elasticsearch. – ChickenWing24 Jun 24 '15 at 07:08
  • On mac you may have to do the following: `cd /usr/local/Library` `git pull origin master` http://apple.stackexchange.com/questions/153790/how-to-fix-brew-after-osx-upgrade-to-yosemite – Alexei Blue Feb 29 '16 at 10:52
  • ES will complain about the `--config` option now - start it with just `elasticsearch` – metadaddy Jun 03 '16 at 22:35
  • does launchctl do that elasticsearch will start a computer reboot automatically ? – Slowwie Sep 18 '16 at 06:26
  • ERROR: config is not a recognized option for --config – Basit Oct 28 '16 at 00:53
  • As far as I can tell there isn't a brew formula for elasticsearch 5. pickypg's instructions worked for me. On thing that's not clear is what is the proper folder. I just ended up putting the un-archived directories into ~/Applications. The same instruction steps work for logstash and kibana as well. The biggest hurdles were getting the right version of Java,(not that hard) and getting the JDBC plugin working. Setting the JAVA_HOME env variable is critical to the success of this. Elasticsearch doesn't seem to care. – Craig Jacobs Dec 04 '16 at 19:55
  • @CraigJacobs I think you're mistaken about there not being a brew formula for elasticsearch 5. You probably forgot to run `brew update`. brew has been on version 5 since Oct 27: https://github.com/Homebrew/homebrew-core/commits/master/Formula/elasticsearch.rb – bobics Dec 11 '16 at 09:13
  • You can also use [brew services](https://robots.thoughtbot.com/starting-and-stopping-background-services-with-homebrew), so `brew services start elasticsearch` will do the same thing – jbejar Mar 14 '17 at 19:14
  • I am finding that brew is not a terribly useful option unless the version you want to install also happens to be exactly the same as the version brew has a recipe for at the time. It's too bad brew doesn't let you specify the version to install, like portage... – Hakanai Jul 27 '17 at 00:01
  • Just installed the `Elasticsearch` with `brew` and works like a charm. I have Java 8 installed in the machine – Arefe Aug 21 '18 at 10:56
  • I get a warning **Warning: elasticsearch has been deprecated because it is switching to an incompatible license!**, is it still okay to use `homebrew` installation? And what is this deprecation warning about, exactly? – aspiring1 Mar 29 '21 at 17:49
29

As there are not very good instructions for actually "installing" it onto a Mac:

Short Version:

  1. Install Java (prefer latest supported release)
  2. Set JAVA_HOME environment variable.
  3. Download Elasticsearch version (tar or zip).
  4. Extract Elasticsearch from the downloaded file.
  5. Run bin/elasticsearch from the extracted directory.

Long version:

  1. Download Java

    • Only need the JRE if you will not be writing code on the same machine.

    • I assume that you are getting the latest JDK, which is currently JDK 8 (as you appear to have, and I have installed working on my machine).

  2. Download and extract Elasticsearch and extract it into some directory.

    1. For example: mkdir -p ~/dev/elasticsearch
    2. Optionally move the downloaded file to there:

      mv Downloads/elasticsearch* ~/dev/elasticsearch

    3. Extract the downloaded file:

      cd ~/dev/elasticsearch (if you moved it in step 2)

      • If it's the zip, then unzip elasticsearch-1.1.0.zip (or if you don't want to cd into the directory, then just run unzip elasticsearch-1.1.0.zip -d ~/dev/elasticsearch)

      • If it's the tar, then tar -xvf elasticsearch-1.1.0.tar.gz (or if you don't want to cd into the directory, then just run tar -xvf elasticsearch-1.1.0.tar.gz -C ~/dev/elasticsearch)

    4. Cleanup (if you want) by removing the downloaded file:

      rm elasticsearch-1.1.0.*

  3. Open your .bash_profile file for your bash profile settings:

    vi ~/.bash_profile

  4. In the file, export your environment variable(s)

    export ES_HOME=~/dev/elasticsearch/elasticsearch-1.1.0

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home

    export PATH=$ES_HOME/bin:$JAVA_HOME/bin:$PATH

    • Close and re-open your Terminal OR

    • Run source ~/.bash_profile to update the environment variables

  5. Run Elasticsearch:

    elasticsearch

    • The more traditional way to run it is to do pretty much all of the above, but not add $ES_HOME/bin to the PATH. Then, just go to ES_PATH (cd $ES_PATH, then bin/elasticsearch) or run $ES_PATH/bin/elasticsearch.

Note: Do not setup your CLASSPATH without a very good reason. The scripts will do that for you.

pickypg
  • 22,034
  • 5
  • 72
  • 84
  • This option was my preference as I have conflicts between brew and macports, so much easier to just download it and install it as above. – Dan Smart Feb 02 '16 at 14:32
8
  1. You should try to using brew with last update:

    brew update
    
  2. And install Cask java:

    brew cask install java
    
  3. After that you can install elasticsearch:

    brew install elasticsearch
    
  4. And to have launched start elasticsearch now use:

    brew services start elasticsearch
    

    Or you can just run:

    elasticsearch
    
AlexSh
  • 1,468
  • 15
  • 12
2

To update ElasticSearch, just run brew upgrade elasticsearch

netwire
  • 7,108
  • 12
  • 52
  • 86
1

Update your java

brew update
brew cask install java

Install it with homebrew brew install elasticsearch

ChrisF
  • 134,786
  • 31
  • 255
  • 325
alytvynov
  • 81
  • 12
0

install gpg && install java or jdk

1-Import the repository’s GPG key:

wget -qO - https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
    
2-this is code repository elasticserach in linux for download

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

3-link download elasticsearch

  https://www.elastic.co/downloads/elasticsearch

if error "Job for elasticsearch.service failed because a timeout was exceeded. See "systemctl status elasticsearch.service" and "journalctl -xe" for details."

solution:

1-sudo journalctl -f

2-sudo systemctl enable elasticsearch.service

3-sudo systemctl start elasticsearch

Netwons
  • 1,170
  • 11
  • 14