In this article, we’ll guide you through the process of installing CockroachDB on Debian 12. CockroachDB is a distributed SQL database that’s built for cloud applications. It offers high availability, fault tolerance, and strong consistency, making it an excellent choice for developers seeking a scalable and resilient database solution.
Prerequisites
Before you begin, make sure you have the following:
- A server running Debian 12 (Bookworm).
- A fresh OS install is recommended to avoid potential issues.
- SSH access to the server or an open Terminal if you’re on a desktop.
- An active internet connection to download the necessary packages and dependencies for CockroachDB.
- A user account with sudo privileges to execute administrative commands.
Installing CockroachDB on Debian 12 Bookworm
Step 1: Update Your System
Keeping your system updated is crucial for security and performance. Start by updating your package list and upgrading existing packages:
sudo apt update sudo apt upgrade
Next, install the required dependencies. curl
is used for downloading files from the internet, and tar
is for extracting compressed files:
sudo apt install curl tar
Step 2: Download and Install CockroachDB
Download the latest version of the CockroachDB binary for Linux. Please check the official CockroachDB documentation for the latest version:
curl https://binaries.cockroachdb.com/cockroach-v23.2.0.linux-amd64.tgz-output cockroach-v23.2.0.linux-amd64.tgz
Extract the downloaded archive:
tar -xzf cockroach-v23.2.0.linux-amd64.tgz
Move the CockroachDB binary to a directory within your PATH
for easy execution:
sudo cp -i cockroach-v23.2.0.linux-amd64/cockroach /usr/local/bin/
Verify the installation by checking the installed version of CockroachDB:
cockroach version
Step 3: Initialize and Run CockroachDB
Start a single-node CockroachDB cluster in insecure mode, suitable for development:
cockroach start-single-node --insecure --listen-addr=localhost:26257 --http-addr=localhost:8080 --background
Here’s what the flags mean:
--insecure
: Starts the node in insecure mode. For development purposes only. Secure mode is recommended for production.--listen-addr
: Specifies the address for listening to SQL client connections.--http-addr
: Specifies the address for the web UI.--background
: Runs the process in the background.
Step 4: Access CockroachDB
Access the SQL shell with the following command:
cockroach sql --insecure --host=localhost:26257
You can also access the CockroachDB Web UI by visiting http://your-IP-address:8080
in your web browser, where you can monitor cluster health and performance.
Step 5: Create a Database and Table (Optional)
Inside the SQL shell, you can create a new database and table:
CREATE DATABASE mydb; USE mydb; CREATE TABLE mytable (id INT PRIMARY KEY, name STRING);
Congratulations! You’ve successfully installed CockroachDB on Debian 12 Bookworm. For further assistance or more useful information, we recommend checking the official CockroachDB website.
If you find that managing VPS and databases isn’t your forte, or you simply don’t have the time, you can take advantage of managed services like Shape.Host Linux SSD VPS. Starting from just $4, you can leave the management to the experts and focus on what you do best.