Me Health CH
Published © Apache-2.0

Installing CouchDB on Raspbian Stretch

This is a step by step explanation on how to install CouchDB 2.x on Raspbian Stretch.

BeginnerProtip30 minutes7,093
Installing CouchDB on Raspbian Stretch

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1

Software apps and online services

CouchDB
Raspberry Pi Raspbian Stretch

Story

Read more

Code

Shell Command Summary

Markdown
# 2. Prerequisite for the Raspberry Pi. #

	cat /etc/os-release
	
	# PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
	# NAME="Raspbian GNU/Linux"
	# VERSION_ID="9"
	# VERSION="9 (stretch)"
	# ID=raspbian
	# ID_LIKE=debian
	# HOME_URL="http://www.raspbian.org/"
	# SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
	# BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
	
	
	sudo apt-get update
	sudo apt-get dist-upgrade

---

# 3. Download, build and install software. #

	wget http://packages.erlang-solutions.com/debian/erlang_solutions.asc
	sudo apt-key add erlang_solutions.asc
	sudo apt-get update
	
	sudo apt-get --no-install-recommends -y install build-essential \
	pkg-config erlang libicu-dev \
	libmozjs185-dev libcurl4-openssl-dev
	
	sudo useradd -d /home/couchdb couchdb
	sudo mkdir /home/couchdb
	sudo chown couchdb:couchdb /home/couchdb
	
	cd
	
	wget http://mirror.ibcp.fr/pub/apache/couchdb/source/2.1.1/apache-couchdb-2.1.1.tar.gz   
	
	tar zxvf apache-couchdb-2.1.1.tar.gz
	cd apache-couchdb-2.1.1/
	
	./configure
	make release
	
	cd ./rel/couchdb/
	sudo cp -Rp * /home/couchdb
	sudo chown -R couchdb:couchdb /home/couchdb
	
	cd
	rm -R apache-couchdb-2.1.1/
	rm apache-couchdb-2.1.1.tar.gz
	rm erlang_solutions.asc

---

# 4. First run and check. #

For remote access:

	sudo nano /home/couchdb/etc/local.ini

=> change line

	#bind_address = 127.0.0.1

to:

	bind_address = 0.0.0.0

(! not prefixed by # !)

Now, you are ready to run CouchDB as couchdb user with:
	
	sudo -i -u couchdb /home/couchdb/bin/couchdb

---

# 5. Script for running CouchDB on boot. #

	mkdir /var/log/couchdb/
	sudo chown couchdb:couchdb /var/log/couchdb
	
Then, be sure that CouchDB is still running and in your Browser go into the Configuration page: [http://127.0.0.1:5984/_utils/#/_config](http://127.0.0.1:5984/_utils/#/_config). If you have defined an administrator you should be logged in as the administrator.

Click on the +Add Option and fill the form like here:

values are:

- `log` for Section,
- `file` for Name and 
- `/var/log/couchdb/couch.log` for Value.

Click on Create.

Now, create the service by editing a new file:

	sudo nano /lib/systemd/system/couchdb.service

and paste the following to the content of the editor:

	[Unit]
	Description=CouchDB Service
	After=network.target
	  
	[Service]
	Type=idle
	User=couchdb
	Restart=always
	ExecStart=/home/couchdb/bin/couchdb
	  
	[Install]
	WantedBy=default.target
	
Then, fix file permissions with:

	sudo chmod 644 /lib/systemd/system/couchdb.service

and instruct systemd to start the service during the boot sequence:

	sudo systemctl daemon-reload
	sudo systemctl enable couchdb.service

When you reboot the Pi the couchdb service should run:

	sudo reboot

and check service status using:

	sudo systemctl status couchdb.service

Also, either browse to page http://localhost:5984 to check that CouchDB server is up and running, or execute in your terminal:

	curl http://localhost:5984

which should reply something like :

	{"couchdb":"Welcome","version":"2.1.1","features":["scheduler"],"vendor":{"name":"The Apache Software Foundation"}}

Now, you are ready to enjoy all CouchDB server capabilities !

Have a look to CouchDB Documentation and enjoy PouchDB in your browser, mobile or NodeJS projects.

Your Feedback and suggestions for improvements would be welcome !  
joel

Credits

Me Health CH

Me Health CH

1 project • 0 followers
eHealth R&D, mobile and personal health, medical informatics research and development

Comments