This article is going to take you through how to install CockroachDB on Ubuntu 22.04. CockroachDB is a serverless distributed SQL database built for building, scaling, and managing modern, data-intensive applications in the cloud. It’s based on a key-value store that’s transactional and very consistent. It scales horizontally, survives disk, machine, rack, and even data center failures with minimal latency and no user intervention, supports strongly-consistent ACID transactions, and provides a familiar SQL API for data organization, manipulation, and querying.
How to Install CockroachDB on Ubuntu 22.04
- Navigate to the CockroachDB website to get the latest download link. Then download and extract it using the following command.
curl https://binaries.cockroachdb.com/cockroach-v22.1.0.linux-amd64.tgz | tar -xz && sudo cp -i cockroach-v22.1.0.linux-amd64/cockroach /usr/local/bin/
- Next copy the CockroachDB executable file to
/usr/local/lib/cockroach
, lets start by creating the directory using the command below.
sudo mkdir -p /usr/local/lib/cockroach
- After creating the directory, copy the library files.
sudo cp -i cockroach-v22.1.0.linux-amd64/lib/libgeos.so /usr/local/lib/cockroach/
sudo cp -i cockroach-v22.1.0.linux-amd64/lib/libgeos_c.so /usr/local/lib/cockroach/
- Confirm the copied binary is working using the command below.
which cockroach
Sample output
/usr/local/bin/cockroach
- Confirm the CockroachDB version installed.
cockroach version
Sample output
Build Tag: v22.1.0 Build Time: 2022/05/23 16:27:47 Distribution: CCL Platform: linux amd64 (x86_64-pc-linux-gnu) Go Version: go1.17.6 C Compiler: gcc 6.5.0 Build Commit ID: 5b78463ed2e7106a8477b63fa837564ad02bb510 Build Type: release
Start single node CockroachDB cluster on Ubuntu 22.04
- Let us create a demo single node cluster using the following commands.
cockroach start-single-node \
--insecure \
--store=commerce_database \
--listen-addr=localhost:26257 \
--http-addr=localhost:8080 \
--background
- Next start CockroachDB shell using the command below.
cockroach sql --insecure --host=localhost:26257
- Then create a user.
CREATE USER itnixpro;
- Create database.
CREATE DATABASE demo_db;
- Set demo_db as the default database.
SET DATABASE = demo_db;
- Grant all privileges to itnixpro user
GRANT ALL ON DATABASE demo_db TO itnixpro;
- To show created database run the following command.
SHOW database;
- Exit the shell using the command below.
\q
Sample output
# # Welcome to the CockroachDB SQL shell. # All statements must be terminated by a semicolon. # To exit, type: \q. # # Server version: CockroachDB CCL v22.1.0 (x86_64-pc-linux-gnu, built 2022/05/23 16:27:47, go1.17.6) (same version as client) # Cluster ID: 1c7359bd-3dc6-4ec9-9d2b-7710c09dfaf3 No entry for terminal type "xterm-256color"; using dumb terminal settings. # # Enter \? for a brief introduction. # root@localhost:26257/defaultdb> CREATE USER itnixpro; CREATE ROLE Time: 100ms total (execution 100ms / network 1ms) root@localhost:26257/defaultdb> CREATE DATABASE demo_db; CREATE DATABASE Time: 19ms total (execution 19ms / network 0ms) root@localhost:26257/defaultdb> SET DATABASE = demo_db; SET Time: 6ms total (execution 5ms / network 1ms) root@localhost:26257/demo_db> GRANT ALL ON DATABASE demo_db TO itnix pro; NOTICE: grant options were automatically applied but this behavior is deprecated HINT: please use WITH GRANT OPTION GRANT Time: 69ms total (execution 68ms / network 1ms) root@localhost:26257/demo_db> SHOW database; database ------------ demo_db (1 row) Time: 2ms total (execution 1ms / network 0ms) root@localhost:26257/demo_db> \q
Access CockroachDB Web Interface
- Fire up your favorite web browser and enter your server/domain name followed by port 8080 and hit enter e.g.
server-IP:8080
orlocalhost:8080
as shown below.
You can now monitor your database from the web interface. Note, that the web interface cannot be used to create databases.
- Click on metrics and select a specific module and time to monitor the metrics.
- Click on Jobs to see running jobs.
- You have made it to the end of our article, Congrats! You have gone through how to install CockroachDB on Ubuntu 22.04.
Read more on CockroachDB Documentation
Other Tutorials
Install MongoDB compass GUI on Ubuntu 22.04