1

I execute the command sudo cassandra -R to start cassandra and I get the following error.

getopt: invalid option -- 'R'
/usr/sbin/cassandra: 158: exec: java: not found

It points to the following line in the cassandra script.

else
        exec $NUMACTL "$JAVA" $JVM_OPTS $cassandra_parms -cp "$CLASSPATH"

Is it because the environment variable JAVA is not set? If yes, how to set the variable?

The output of echo $JAVA_HOME is blank. This is the output of java -version:

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
3

1 Answer 1

0

A simple solution for that is to set JAVA_HOME variable to point to your java installation. The cassandra script should generally autodeetect your java location on PATH, but if it doesn't happen, you can help with setting JAVA_HOME explicitly:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/

Note: you must set JAVA_HOME not JAVA. JAVA variable is used internally by the cassandra launch scripts, but you're not supposed to set it. JAVA is set by this code snippet in cassandra.in.sh:

# Use JAVA_HOME if set, otherwise look for java in PATH
if [ -n "$JAVA_HOME" ]; then
    # Why we can't have nice things: Solaris combines x86 and x86_64
    # installations in the same tree, using an unconventional path for the
    # 64bit JVM.  Since we prefer 64bit, search the alternate path first,
    # (see https://issues.apache.org/jira/browse/CASSANDRA-4638).
    for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
        if [ -x "$java" ]; then
            JAVA="$java"
            break
        fi
    done
else
    JAVA=`command -v java 2> /dev/null`
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.