How to Install Apache CouchDB 3.1 on Ubuntu 20.04 LTS

Apache CouchDB is a NoSQL open-source document-oriented database system written in Erlang, JavaScript, C, and C++. It uses JSON to store data. Documents can be accessed with your web browser. It is primary used for running queries and creating reports from documents files.

CouchDB comes with features such as on-the-fly document transformation, real-time change notifications, high availability, distributed scaling, partition tolerance, and more. It comes with a web administration interface.

In this tutorial, we learn how to install CouchDB on Ubuntu 20.04 using the convenience binary packages.

Step 1: Add the CouchDB GPG key

First, let's add the CouchDB GPG key. To fetch the official CouchDB repo key, type:

$ curl https://couchdb.apache.org/repo/keys.asc | gpg --dearmor > couchdb-repo-keyring.gnp && sudo mv couchdb-repo-keyring.gnp /usr/share/keyrings/

Step 2: Enable the CouchDB repository

To enable the CouchDB repository, run the following command:

$ echo "deb [signed-by=/usr/share/keyrings/couchdb-repo-keyring.gnp] https://apache.jfrog.io/artifactory/couchdb-deb focal main" > couchdb.list && sudo mv couchdb.list /etc/apt/sources.list.d/

Step 3: Update the Ubuntu system

Update your Ubuntu system and get the latest package information:

$ sudo apt update

Step 4: Install CouchDB on Ubuntu

You can now install CouchDB using the apt command:

$ sudo apt-get install -y couchdb

As part of the installation, you should see a CouchDB setup wizard popup. This Wizard helps to pre-configure CouchDB as a standalone or clustered node, IP address to which it will bind, and a password for the admin user.

Hit the 'Enter' key to continue with setup
Select 'standalone' and hit the Enter key.
Hit 'Enter' to set the bind address
Choose a password and hit Enter
Repeat the password and hit Enter

CouchDB cluster and standalone mode use port 5984. For clustering, it uses Erlang-native clustering - using port 4369. If you have a firewall, make sure these ports are open.

Step 6: Verify CouchDB installation

Upon installation, CouchDB should already be running and ready to use. CouchDB is installed in the directory /opt/couchdb.

To be sure the installation was successful, try access the Couchdb server URL from the terminal.

$ curl http://127.0.0.1:5984

The output showing the version, among other general information, of the CouchDB installation:

{
    "couchdb" : "Welcome",
    "features" : [
       "access-ready",
       "partitioned",
       "pluggable-storage-engines",
       "reshard",
       "scheduler"
    ],
    "git_sha" : "ce596c65d",
    "uuid" : "4433afd11f516283786140ffafdaee5c",
    "vendor" : {
       "name" : "The Apache Software Foundation"
    },
    "version" : "3.1.1"
 }

You can see that we have installed CouchDB version 3.1.

The default username is 'admin' and you should have chosen a password.

To create a database, the syntax is "http://{username}:{password}@127.0.0.1:5984/{your new database}".

For example:

$ curl -X PUT "http://admin:sample_password@127.0.0.1:5984/sample_database"

The output confirming the successful creation of the database:

{
    "ok" : true
 }

To list all CouchDB databases, type:

$ curl -X GET http://admin:sample_password@127.0.0.1:5984/_all_dbs

Output:

[
    "_replicator",
    "_users",
    "sample_database"
 ]

Step 6: Access CouchDB Web interface

CouchDB has a built-in Web interface to create, update, delete and view documents and design documents.

To access the CouchDB web interface, point your preferred browser to http://127.0.0.1:5984/_utils/.

CouchDB Web interface login
CouchDB Web interface login
List databases
List databases

Conclusion

In this tutorial, we learned how to install CouchDB on Ubuntu 20.04. If you have any questions, suggestions, feedback please write them in the comment box below.

Leave a Comment