How To Install CockroachDB on Ubuntu 22.04 LTS
In this tutorial, we will show you how to install CockroachDB on Ubuntu 22.04 LTS. CockroachDB is favored for its resilience, as it provides strong consistency and can survive hardware or network failures. It’s particularly well-suited for applications that demand high availability and low-latency access to data.
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 Ubuntu 22.04. You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
- 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
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install CockroachDB on Ubuntu 22.04 LTS Jammy Jellyfish
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Install Required Dependencies.
CockroachDB has certain dependencies that need to be installed. Use the following command to install them:
sudo apt install -y curl lsof wget
Step 3. Installing CockroachDB on Ubuntu 22.04.
Now, let’s proceed with downloading the latest version of CockroachDB:
wget https://binaries.cockroachdb.com/cockroach-latest.linux-amd64.tgz
After downloading, it’s time to extract the files from the downloaded archive. Use the following command:
tar -xvzf cockroach-latest.linux-amd64.tgz
CockroachDB is a single binary executable. To make it accessible system-wide, move it to a directory listed in your system’s PATH:
sudo mv cockroach /usr/local/bin/
Now, it’s crucial to create a data directory where CockroachDB will store its data:
mkdir -p ~/cockroach-data
Initialize a new CockroachDB node using the following command:
cockroach init --insecure --host=localhost
The ‘--insecure
‘ flag allows for quick setup without encryption. In production environments, you should use secure configurations.
Step 4. Configuring CockroachDB.
CockroachDB needs configuration before it can be used effectively. You must specify the IP address and port CockroachDB should listen on. Edit the cluster settings in the ‘cockroach’ binary:
cockroach start --background --store=path-to-your-data-directory \ --listen-addr=<your-ip-address> --http-addr=<your-ip-address>:8080
Replace <your-ip-address>
with your system’s IP address.
Assign a unique cluster name to your CockroachDB instance. For example:
--join=<your-ip-address>:26257 --locality=region=us,zone=us-west
To start CockroachDB, use the following command:
cockroach start --background --store=path-to-your-data-directory \ --listen-addr=<your-ip-address> --http-addr=<your-ip-address>:8080
Step 5. Access the CockroachDB Admin UI.
To access the CockroachDB Admin UI, open your web browser and navigate to:
http://<your-ip-address>:8080
Congratulations! You have successfully installed CockroachDB. Thanks for using this tutorial for installing CockroachDB on the Ubuntu system. For additional help or useful information, we recommend you check the official CockroachDB website.