11

I am trying to set JAVA_HOME so that I can install Apache Solr with the help of this tutorial. I am connected to my server using ssh with root user

To allow the running sh script to install Apache Solr:

mount | grep noexec

Re-mounting file system with exec option:

mount -o remount,exec /dev/md1

Then every time I try to install it using the following commands

bin/install_solr_service.sh /tmp/solr-5.3.1.tgz

I get the following message:

WARNING: /opt/solr-5.3.1 already exists! Skipping extract ...

Creating /etc/init.d/solr script ...
The currently defined JAVA_HOME (/usr/local/jdk) refers
to a location where Java could not be found.  Aborting.
Either fix the JAVA_HOME variable or remove it from the
environment so that the system PATH will be searched.
The currently defined JAVA_HOME (/usr/local/jdk) refers
to a location where Java could not be found.  Aborting.
Either fix the JAVA_HOME variable or remove it from the
environment so that the system PATH will be searched.
Service solr installed.

This is what I tried so far:

nano /root/.bash_profile 
nano /etc/profile

I added the following to the files above at the end and saved them

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64
export PATH=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/bin:$PATH

That didn't work.

I created the following file /etc/profile.d/java.sh and put in it:

export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/
export PATH=$PATH:$JRE_HOME/bin

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64
export JAVA_PATH=$JAVA_HOME

export PATH=$PATH:$JAVA_HOME/bin

And ran the following command:

source java.sh

That also didn't work.

I tried to run the following command:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64

No luck at all.

But when a run the following commands that is what I get

echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64
echo $PATH
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/bin:/usr/local/jdk/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre//bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin
Waqleh
  • 269
  • 1
  • 2
  • 10

3 Answers3

15

You want to point JAVA_HOME to the JRE directory, as in:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre/

If using bash, I recommend putting this in /etc/bashrc (RH based) or /etc/bash.bashrc (Debian based):

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • Assuming you have a link for Java here. This is more a Debian specific thing, please change accordingly for CentOS – Rui F Ribeiro Nov 18 '15 at 14:01
  • 1
    CentOS 7 here, works. – Jodka Lemon Nov 18 '15 at 14:44
  • 1
    This worked for me only after overwriting JAVA_HOME inside `/etc/bashrc` – ovi Feb 22 '16 at 21:08
  • @ovi I am using Debian, what is your distro? – Rui F Ribeiro Feb 23 '16 at 07:37
  • @RuiFRibeiro Centos 6.7. Maybe it's also worth mentioning that `/etc/bashrc` already contained following: `export JAVA_HOME=/usr/local/jdk` `export PATH=$JAVA_HOME/bin:$PATH` `export CLASSPATH=.:$JAVA_HOME/lib/classes.zip` – ovi Feb 23 '16 at 11:33
  • Thanks @ovi, I am changing the answer from /etc/profile to /etc/bashrc as it is more compatible with bash. – Rui F Ribeiro Feb 23 '16 at 11:38
  • cool, glad I could help. maybe you can also remove the trailing slash from the directory, so no double slashes appear when using it to form new paths? e.g. use `sed "s:/bin/java::"` – ovi Feb 23 '16 at 11:43
  • It has not done any difference for me in years, or perhaps I did not notice. Changed; will check out later on more about that, thanks. (I am not a Java developer, thanks for the pointers) – Rui F Ribeiro Feb 23 '16 at 12:00
  • Usually JAVA_HOME points to JDK, not JRE - [Should JAVA_HOME point to JDK or JRE?](https://stackoverflow.com/questions/17601827/should-java-home-point-to-jdk-or-jre) – kodstark Dec 07 '22 at 11:30
1

Rather than copying out files from the installation directory it would be better to set the SOLR_JAVA_HOME in /etc/default/solr.in.sh to the location of the jre folder in your installation such as usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/

Sam
  • 19
  • 1
0

I was reading my question and found the answer in it. This is what I have done:

I have undone all the changes to /root/.bash_profile and /etc/profile

Then I created a folder called jdk in the /usr/local/ folder like so

mkdir /usr/local/jdk

Since this is were the jdk is expected to be located in. Then I copied the jdk files to that newcp -R /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/* /usr/local/jdk/ folder like so:

cp -R /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/* /usr/local/jdk/

As simple as that I was now able to install Apache Solr

Waqleh
  • 269
  • 1
  • 2
  • 10