DebianDebian Based

How To Install CockroachDB on Debian 12

Install CockroachDB on Debian 12

In this tutorial, we will show you how to install CockroachDB on Debian 12. CockroachDB is a distributed SQL database that is designed for cloud applications, offering high availability, fault tolerance, and strong consistency. It is an excellent choice for developers looking for a scalable and resilient database solution.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of CockroachDB on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for CockroachDB.
  • A user account with sudo privileges to execute administrative commands.

Install CockroachDB on Debian 12 Bookworm

Step 1. Keeping your system up to date is crucial for security and performance. Begin 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. Installing CockroachDB on Debian 12.

Download the latest version of the CockroachDB binary for Linux. As of the last update, the command below is an example; always 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/

Check the installed version of CockroachDB to verify the installation:

cockroach version

Step 3. Start CockroachDB.

 Initialize and 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
  • --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 using the following command:

cockroach sql --insecure --host=localhost:26257

You can also access the CockroachDB Web UI visit http://your-IP-address:8080 in your web browser to access the CockroachDB Web UI, where you can monitor cluster health and performance.

Install CockroachDB on Debian 12 Bookworm

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 have successfully installed CockroachDB. Thanks for using this tutorial to install the latest version of the CockroachDB on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official CockroachDB website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button