Inspired by: https://cassandra.apache.org/doc/latest/cassandra/getting-started/index.html
Note: Stick to Java 17.
Installing a more recent version (Java 17+) will fail when running Cassandra with error:
Exception (java.lang.UnsupportedOperationException) encountered during startup: The Security Manager is deprecated and will be removed in a future release
sudo apt-get install openjdk-17-jre
sudo update-alternatives --config java
Note: Install Python v3.8-3.11 or above.
In this example, we will install Python v3.13
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.13
cd $HOME
curl -OL https://archive.apache.org/dist/cassandra/5.0.2/apache-cassandra-5.0.2-bin.tar.gz
Compare the signature with the SHA256 file:
curl -L https://archive.apache.org/dist/cassandra/5.0.2/apache-cassandra-5.0.2-bin.
tar.gz.sha256
The result shoud be equal to:
d721834207838b9d01919dfc33625ad17b50fea03bf9f76cdd8d3ae3a8fd2947
tar xzvf apache-cassandra-5.0.2-bin.tar.gz
mkdir cassandra-store && cd $_
~/apache-cassandra-5.0.2/bin/cassandra
nano data.cql
Paste this content, and then save the
data.cql
file:
CREATE KEYSPACE IF NOT EXISTS store WITH REPLICATION =
{ 'class' : 'SimpleStrategy',
'replication_factor' : '1'
};
CREATE TABLE IF NOT EXISTS store.shopping_cart (
userid text PRIMARY KEY,
item_count int,
last_update_timestamp timestamp
);
INSERT INTO store.shopping_cart
(userid, item_count, last_update_timestamp)
VALUES ('9876', 2, toTimeStamp(now()));
INSERT INTO store.shopping_cart
(userid, item_count, last_update_timestamp)
VALUES ('1234', 5, toTimeStamp(now()));
~/apache-cassandra-5.0.2/bin/cqlsh -f ./data.cql
~/apache-cassandra-5.0.2/bin/cqlsh -e "SELECT * FROM store.shopping_cart;"