On this page
- What is CouchDB good for?
- How do you add the repository and install CouchDB?
- How do you check that CouchDB is running?
- Where is the configuration and what should you change?
- How do you create databases and app users?
- How do you use Fauxton safely?
- How do you expose CouchDB over HTTPS?
- How do you back up, upgrade and troubleshoot CouchDB?
- Questions
What is CouchDB good for?
CouchDB stores JSON documents, speaks plain HTTP for every operation and replicates between servers and devices, even over unreliable links. That makes it a strong fit for offline-first mobile and browser apps that sync through PouchDB, for audit logs and for any data that several sites need to keep in step.
Every request is an HTTP call, so you can manage the database with curl, a browser or any HTTP library. Documents carry a revision number, which lets two copies change independently and reconcile later. Queries use views (map and reduce functions) or Mango, a JSON query language with indexes.
The official packages cover Ubuntu and Debian LTS releases, so this guide uses those. A single node runs well on 1 to 2 GB of RAM for a small app. Start from a fresh Ubuntu 24.04 or Debian 12 server with a sudo user.
How do you add the repository and install CouchDB?
Import the project signing key, add the repository line for your release codename and install the package. The installer then asks a few questions.
sudo apt update
sudo apt install -y curl apt-transport-https gnupg
curl -fsSL https://couchdb.apache.org/repo/keys.asc | gpg --dearmor | sudo tee /usr/share/keyrings/couchdb-archive-keyring.gpg >/dev/null
source /etc/os-release
echo "deb [signed-by=/usr/share/keyrings/couchdb-archive-keyring.gpg] https://apache.jfrog.io/artifactory/couchdb-deb/ ${VERSION_CODENAME} main" | sudo tee /etc/apt/sources.list.d/couchdb.list
sudo apt update
apt policy couchdb
sudo apt install -y couchdbIf apt update reports that your codename has no release file, the repository does not build for that release yet; use the newest supported LTS release instead. Answer the prompts like this:
- General type of configuration: standalone.
- Erlang magic cookie: any long random string; it only matters for clusters.
- Bind address:
127.0.0.1. - Admin password: a long random value, stored in a password manager.
Standalone mode sets single_node = true, which creates the _users and _replicator system databases automatically.
How do you check that CouchDB is running?
Query the root and health endpoints with curl; both answer with small JSON documents.
sudo systemctl status couchdb --no-pager
sudo ss -ltnp | grep 5984
curl -s http://127.0.0.1:5984/
curl -s http://127.0.0.1:5984/_up
curl -s -u admin http://127.0.0.1:5984/_all_dbsThe root response includes the version number and a welcome line. The last command prompts for the admin password and should list _replicator and _users. Port 4369 (the Erlang port mapper) may also appear in ss; it is only needed for clustering and must stay closed in the firewall.
Where is the configuration and what should you change?
Local settings go in /opt/couchdb/etc/local.ini or, better, in small files under /opt/couchdb/etc/local.d/, which upgrades never touch. Defaults in default.ini should not be edited.
A sensible hardening file, /opt/couchdb/etc/local.d/10-site.ini:
[chttpd]
bind_address = 127.0.0.1
port = 5984
require_valid_user = true
max_http_request_size = 67108864
[couchdb]
max_document_size = 8000000
[log]
level = warningrequire_valid_user refuses every anonymous request, including reads of the welcome page, so the database is never browsable without credentials. After saving, fix ownership and restart:
sudo chown couchdb:couchdb /opt/couchdb/etc/local.d/10-site.ini
sudo systemctl restart couchdb
curl -s http://127.0.0.1:5984/_up # now 401 without credentials
curl -s -u admin http://127.0.0.1:5984/_upAdmin passwords in the [admins] section are hashed automatically on the next start; never leave a plain text copy elsewhere.
How do you create databases and app users?
Create a database with a PUT, create a user document in _users, and list that user as a member in the database security object. Members can read and write documents but cannot change design documents or security settings.
curl -u admin -X PUT http://127.0.0.1:5984/orders
curl -u admin -X PUT http://127.0.0.1:5984/_users/org.couchdb.user:shop \
-H 'Content-Type: application/json' \
-d '{"name":"shop","password":"App-Secret-Value-55","roles":[],"type":"user"}'
curl -u admin -X PUT http://127.0.0.1:5984/orders/_security \
-H 'Content-Type: application/json' \
-d '{"admins":{"names":[],"roles":[]},"members":{"names":["shop"],"roles":[]}}'Test as the app user:
curl -u shop -X POST http://127.0.0.1:5984/orders -H 'Content-Type: application/json' -d '{"item":"vps","qty":1}'
curl -u shop http://127.0.0.1:5984/orders/_all_docsNew databases in CouchDB 3 are admin-only until you set members, which is a safe default.
How do you use Fauxton safely?
Reach the built-in web interface through an SSH tunnel instead of opening port 5984. On your own computer run:
ssh -N -L 5984:127.0.0.1:5984 deploy@198.51.100.24Then open http://127.0.0.1:5984/_utils/ in your browser and sign in as admin. Fauxton lets you browse documents, write Mango queries, build views and start replications with a few clicks. Close the tunnel when you are done. A deeper look at tunnels lives in remote database access.
How do you expose CouchDB over HTTPS?
Place a reverse proxy before the app that terminates TLS, and keep CouchDB itself on loopback. With Caddy and a DNS record for db.example.net, the whole site block is short:
db.example.net {
reverse_proxy 127.0.0.1:5984
}Caddy fetches and renews the certificate on its own; see Caddy HTTPS and DNS records. Open only ports 80 and 443:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw deny 5984
sudo ufw deny 4369For a browser app on another origin, enable CORS in a local.d file with [chttpd] enable_cors = true and list the exact origins under [cors] origins; avoid a wildcard when credentials are in use. Nginx works too: the nginx reverse proxy guide covers the general pattern.
How do you back up, upgrade and troubleshoot CouchDB?
Back up by replicating to a second CouchDB, or by copying the database files while the server is idle. Replication is the CouchDB way and runs continuously if you want.
curl -u admin -X POST http://127.0.0.1:5984/_replicate \
-H 'Content-Type: application/json' \
-d '{"source":"orders","target":"https://admin:SECRET@backup.example.net/orders","create_target":true}'The raw files live under /opt/couchdb/data/; CouchDB writes them append-only, so a file copy is consistent enough for a restore of that database. Compaction reclaims the space old revisions use:
curl -u admin -X POST http://127.0.0.1:5984/orders/_compact -H 'Content-Type: application/json'Upgrades within the 3.x series arrive with sudo apt upgrade. When the service fails, read sudo journalctl -u couchdb -n 50 --no-pager; usual causes are a config file not owned by couchdb, a syntax error in an ini file or a full disk. Pair replication with the daily backups add-on for a whole-disk copy.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Install Apache CouchDB
What port does CouchDB use?
HTTP on 5984. Port 4369 and a range of Erlang ports are only needed between cluster nodes and should stay closed on a single node.
Is CouchDB compatible with PouchDB?
Yes. PouchDB in the browser or on mobile syncs with CouchDB through the same replication protocol, which is the classic offline-first setup.
How do I reset a lost admin password?
Add a new line under [admins] in a file in /opt/couchdb/etc/local.d/ with a plain text password, then restart. CouchDB hashes it on start.
Can I run CouchDB in a cluster on several servers?
Yes. Install with the clustered option, use the same Erlang cookie on each node, open 4369 and the Erlang distribution ports only between nodes, and join them with the cluster setup API or Fauxton.
Why does every request return 401?
With require_valid_user = true every request needs credentials, including /_up. Pass -u user to curl, or add require_valid_user_except_for_up = true under [chttpd] so an uptime monitor can poll the health endpoint without a password.
More in Databases
- Install MySQL 8
- Install MariaDB
- Install PostgreSQL
- Install MongoDB
- PostgreSQL JSON, arrays and special types
- PostgreSQL views, triggers and CTEs
- PostgreSQL full-text search and encryption
- MySQL keys, indexes and full-text search
- MySQL JSON, views and stored procedures
- Apache Solr search server
- Install Redis or Valkey
- Install Memcached
- Apache Cassandra cluster
- InfluxDB for time series
- Install Elasticsearch
- Back up and restore MySQL and MariaDB
- Back up and restore PostgreSQL
- MySQL users, roles and passwords
- PostgreSQL roles and permissions
- Repair a crashed MySQL table
- PostgreSQL streaming replication
- MongoDB replica set
- PostGIS for location data
- Database insight with PgHero
- Couchbase Server
- ArangoDB multi-model database
- Remote database access over SSH