title: Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server
body: <p>Trying to start Solr with sunspot but having an issue with the Java Runtime Environment by getting this error.</p>
  
  <pre><code>root@oktobTest:~# dokku run oktob bundle exec rake sunspot:solr:start
  rake aborted!
  Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server
  /app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/server.rb:203:in `ensure_java_installed'
  /app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/server.rb:27:in `initialize'
  /app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:38:in `new'
  /app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:38:in `server'
  /app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:10:in `block (3 levels) in &lt;top (required)&gt;'
  Tasks: TOP =&gt; sunspot:solr:start
  (See full trace by running task with --trace)
  </code></pre>
  
  <p>Solar is up and running on the remote server.</p>
  
  <p>Java is installed </p>
  
  <pre><code>root@oktobTest:~# which java
  /usr/bin/java
  </code></pre>
  
  <p>And this is the output of <code>sudo update-alternatives --config java</code></p>
  
  <pre><code>root@oktobTest:~# sudo update-alternatives --config java
  There are 3 choices for the alternative java (providing /usr/bin/java).
  
    Selection    Path                                            Priority   Status
  ------------------------------------------------------------
    0            /usr/lib/jvm/java-8-oracle/jre/bin/java          1073      auto mode
    1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  * 2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1072      manual mode
    3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1073      manual mode
  </code></pre>
  
  <p>I edited <code>/etc/profile</code> file to export the path inspired by discussions <a href="https://stackoverflow.com/questions/20970123/sunspot-solr-not-starting-with-you-need-a-java-runtime-environment-to-run-the-s">here</a> and <a href="https://stackoverflow.com/questions/24534939/rails-4-solr-throwing-javamissing-error-but-java-is-installed">here</a> and <a href="http://javaandme.com/" rel="nofollow noreferrer">javaandme</a></p>
  
  <pre><code>JAVA_HOME=/usr/java/default
  export JAVA_HOME
  PATH=$JAVA_HOME/bin:$PATH
  export PATH
  </code></pre>
  
  <p>I'm not sure about the path above is it correct or not.</p>
  
  <p><code>config/sunspot.xml</code> file</p>
  
  <pre><code>production:
    solr:
      hostname: localhost
      port: 8983
      log_level: WARNING
      path: /solr/production
      # read_timeout: 2
      # open_timeout: 0.5
  
  development:
    solr:
      hostname: localhost
      port: 8982
      log_level: INFO
      path: /solr/development
  
  test:
    solr:
      hostname: localhost
      port: 8981
      log_level: WARNING
      path: /solr/test
  </code></pre>