Apache CouchDB is an open-source non-relational database released in 2005 by the Apache Software Foundation. It focuses on the storage of data in JSON format. This database is made with Erlang, which makes it scalable with a user-friendly experience. It is ideal for web-based applications that require a flexible solution for storing and retrieving data. CouchDB allows production databases to run smoothly with non-interrupted operations regardless of fluctuations in request volume and performance issues.
This blog post will show the steps required to implement the CouchDB database server on Ubuntu 22.04. You might also like the MongoDB database
Prerequisites
Before proceeding, make sure you have:
- Ubuntu 20.04 installed
- A non-root
sudo
user
With that out of the way, let us get started.
Package updates and dependency installation
In the terminal, run the following command to update the packages database.
sudo apt update
The next step is to install the required dependencies. Do so with the command below.
sudo apt install -y curl apt-transport-https gnupg
Configuring the CouchDB repository and Key
-
Copy the following command and paste it on your terminal.
curl https://couchdb.apache.org/repo/keys.asc | gpg --dearmor | sudo tee /usr/share/keyrings/couchdb-archive-keyring.gpg >/dev/null 2>&1 source /etc/os-release
This command should download the CouchDB
gpg
package key to allow theapt
tool to trust the third-party repository. -
The next step is to add the CouchDB repository to the list of downloadable packages with the command below.
echo "deb [signed-by=/usr/share/keyrings/couchdb-archive-keyring.gpg] https://apache.jfrog.io/artifactory/couchdb-deb/ jammy main" | sudo tee /etc/apt/sources.list.d/couchdb.list >/dev/null
-
Update the package database once more to refresh the new repository entry.
sudo apt update
CouchDB installation
-
With the repository ready, install the CouchDB database with the following code and press
Enter
.sudo apt install -y couchdb
The installation will prompt you with a few questions:
-
The first prompt asks for the type of CouchDB configuration:
General type of CouchDB configuration: standalone clustered none
For demonstration purposes, the standalone option is the way to go considering that the DB is installed in a single server.
Use the
up/down arrow keys
to choose the option that fits your needs accordingly, and pressEnter
.Standalone: With this option, only one server is involved.
Clustered: This option has multiple interconnected servers that work together as retrievable data repository.
-
The next prompt asks for the Erlang magic cookie value. You can type anything here but make sure that the value matches for all nodes in the cluster. The Erlang magic cookie is a unique identifier for the clusters. In this case, I use
Geek
as the magic cookie.
-
In the next prompt, Enter the target IP address.
CouchDB interface bind address:
127.0.0.1
Leave the IP address to default `127.0.0.1` for the standalone installation and press `Enter`
-
You are then prompted for an administration password.
Password for the CouchDB "admin" user: EXAMPLE_PASSWORD
Type in your password and re-type it again for confirmation and press
Enter
.Leave the installation process to finish, and you are done.
Verify the Installation
You can confirm the installation was successful and the service is running with the following command.
curl http://127.0.0.1:5984/
The server will be running on the port 5984
.
You can also check using the command below to check the status:
sudo systemctl status couchdb
Managing the CouchDB
You can use the following commands to manage the CouchDB package.
Starting the Service:
sudo systemctl start couchdb
Stopping the Service:
sudo systemctl stop couchdb
Enabling the CouchDB service to start at boot:
sudo systemctl enable couchdb
Restarting the CouchDB service:
sudo systemctl restart couchdb
Accessing CouchDB Web Interface
You can access the Apache CouchDB web interface by visiting http://127.0.0.1:5984/_utils/
. This works for local machines. However, follow the steps below if you have set this up remotely.
-
Start by opening
/opt/couchdb/etc/local.ini
file with nano.sudo nano /opt/couchdb/etc/local.ini
-
Find the
;
character in;bind_address = 127.0.0.1
entry.... [chttpd] ;port = 5984 ;bind_address = 127.0.0.1 ...
-
Remove the
;
character from thebind_address
to uncomment it. Change its value from127.0.0.1
to0.0.0.0
. This will allow CouchDB to listen to all networks.This is how it should look.
... [chttpd] ;port = 5984 bind_address = 0.0.0.0 ...
-
Save the file and restart the CouchDB server to apply the changes.
sudo systemctl restart couchdb
-
You can now visit the url
http://URL:5984/_utils/
. Where URL is your servers' IP address. -
After going to the URL, you see the login screen.
To login to your Fauxton control panel, use the user credentials set earlier with "username" set as "admin"
Conclusion
This article shows a walk-through for the installation of the Apache CouchDB on Ubuntu 22.04. After the installation, you can perform the basic CRUD functions using the CouchDB to manage your files and documents.
If you found the article helpful, consider sharing it and subscribing to geekbits.
Thank you for reading :)