如何移除/etc/apt/sources.list.d对象?并换方式安装Cassandra
Got it, let's walk through removing that Cassandra APT source from /etc/apt/sources.list.d/ and then cover a couple of alternative installation methods. Here's how to do it step by step:
第一步:移除Cassandra的APT源配置
The /etc/apt/sources.list.d/ directory holds separate configuration files for each third-party APT repository. To remove the Cassandra one:
- First, list all files in the directory to find the Cassandra-related config:
Look for a file named something likels /etc/apt/sources.list.d/cassandra.listorcassandra.sources(the exact name depends on how you added it). - Delete the file using sudo (replace
<cassandra-config-file>with the actual filename you found):sudo rm /etc/apt/sources.list.d/<cassandra-config-file> - Update your APT cache to clear references to the removed source:
sudo apt update
If you had previously installed Cassandra via APT, you might also want to purge the old installation and clean up residual files:
sudo apt remove --purge cassandra sudo apt autoremove
第二步:替代安装方式
Here are two reliable alternatives to install Cassandra without using the APT source:
方式1:手动安装二进制包
This gives you full control over the installation directory and version:
- Download the binary tarball for your desired Cassandra version (you can grab it from the official Apache Cassandra site):
Replacewget https://downloads.apache.org/cassandra/<your-desired-version>/apache-cassandra-<your-desired-version>-bin.tar.gz<your-desired-version>with the actual version number (e.g.,4.1.3). - Extract the tarball:
tar -xzf apache-cassandra-<your-desired-version>-bin.tar.gz - Move the extracted directory to a permanent location (like
/opt):sudo mv apache-cassandra-<your-desired-version> /opt/cassandra - Set up environment variables to make Cassandra commands accessible system-wide. Edit your
~/.bashrcfile (or/etc/profilefor all users):
Add these lines at the end:nano ~/.bashrcexport CASSANDRA_HOME=/opt/cassandra export PATH=$PATH:$CASSANDRA_HOME/bin - Apply the environment changes:
source ~/.bashrc - Start Cassandra (use
-fto run in foreground, omit it for background):cassandra -f
方式2:用Docker安装Cassandra
If you prefer containerized deployments, Docker is a quick and clean option:
- First, install Docker if you don't have it already:
sudo apt install docker.io sudo systemctl start docker sudo systemctl enable docker - Pull the Cassandra Docker image for your desired version (use
latestfor the most recent stable version):sudo docker pull cassandra:<your-desired-version> - Start a Cassandra container (maps port 9042, the default CQL port, to your host machine):
sudo docker run -d --name cassandra-container -p 9042:9042 cassandra:<your-desired-version> - Connect to the Cassandra instance using
cqlshinside the container:sudo docker exec -it cassandra-container cqlsh
内容的提问来源于stack exchange,提问作者MikiBelavista

