How to run Cassandra (cqlsh) from anywhere

user4700203 picture user4700203 · Apr 29, 2015 · Viewed 14.3k times · Source

In Cassandra the official documentation (https://wiki.apache.org/cassandra/GettingStarted) it states, to start the service use

'bin/cassandra -f'

Then use

'bin/cqlsh'

to access. But to use cqlsh in this way I always have to go to the bin folder. What is the procedure to make it work such that I can type 'cqlsh' from anywhere in the console to access (not have to be in the bin folder of Cassandra setup) ?

(just like we access python directly from anywhere by just typing python3 in console )

Answer

Aaron picture Aaron · Apr 30, 2015

To get this work work, you have to add your Cassandra bin directory to your $PATH.

From a terminal prompt, check the contents of your $PATH.

$ echo $PATH

On my Ubuntu VM, this is what I see:

/usr/local/apache-maven/apache-maven-3.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.7.0_45/bin

Since you mention Python3, I'll check the location of that on my system as well:

$ which python3
/usr/bin/python3

As you can see, Python3 is in my /usr/bin directory, and /usr/bin is in my $PATH, which is why simply typing python3 works for me (and you as well).

There are a few ways to get your Cassandra bin directory into your $PATH. There is some debate about which is the "correct" way to do accomplish this. So in lieu of telling you how I would do it, I will provide a link to a question on AskUbuntu that details something like 3 ways to add a directory into your $PATH: How to add a directory to my path?