Etcd is a free and open-source distributed and secure key-value store used to store the most critical information of a given distributed system. Etcd is written in Go making it extremely fast in distributed systems without incurring a performance overhead from clustered machines. In this guide, you discover the basics of installing and setting up an etcd cluster on Ubuntu systems.
In this tutorial you will learn:
- What’s the difference between etcd and Redis
- How to Install etcd using official binaries
- How to install ectd from a source code
- How to install etcd from a standard Ubuntu repository
- How to manage etcd service

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Ubuntu 22.10, 22.04, 20.04, and Ubuntu 18.04. |
Software | etcd |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Redis vs Etcd
Etcd and Redis are both distributed systems that store and manage data in a distributed environment, but with some key differences which make each suitable for different use cases.
Distributed key-value store is a type of data storage system that uses a distributed architecture to store data on multiple servers. This type of system can provide a high level of scalability and reliability while maintaining low latency.
Etcd
One of the main features of etcd is its strong consistency model, which ensures that all nodes in the cluster see the same data simultaneously. As a result, it is well-suited for applications that require strong consistency, such as those that need to coordinate the actions of multiple nodes.
Etcd is also highly available, supporting leader election and automatic failover, which means it can continue operating even if some cluster nodes fail. Another key feature of etcd is its support for distributed transactions. This feature allows multiple nodes to make changes to the data in the store in a coordinated way, ensuring that the data remains consistent
Redis
On the other hand, Redis is highly performant. As a result, it is often used to store data that needs to be accessed quickly, such as real-time analytics or high-speed message processing.
Unlike etcd, Redis does not provide strong consistency guarantees. Instead, it uses a “last write wins” model, which means that the most recent write to the data store will overwrite any previous writes. This makes it more suitable for applications that tolerate some level of inconsistency, such as caching systems or real-time analytics.
Installing etcd on Ubuntu
As we will discover in this tutorial, there are various methods of installing etcd on an Ubuntu system.
Installing etcd on Ubuntu Using the Package Manager
We can also install the etcd database on Ubuntu using the APT package manager. We can start by refreshing the system packages with the command:
$ sudo apt-get update
Next, install the etcd database as:
$ sudo apt-get install etcd
Pre-built binary intallation
The most common method is using pre-built binary packages.
- We can start by updating the package repositories and installing the required tools.
Open the command and run the command:$ sudo apt-get update $ sudo apt-get install wget curl -y
Updating the package repositories and installing the required tools - Navigate to the etcd binaries release page on GitHub and select the latest version. Ensure to choose version 3.5 and higher.
etcd binaries release page Download the binary via cURL or wget with the command:
$ wget https://github.com/etcd-io/etcd/releases/download/v3.5.6/etcd-v3.5.6-linux-amd64.tar.gz
Once downloaded, extract the downloaded archive with the command:
$ tar xvf etcd-v3.5.6-linux-amd64.tar.gz
Extract the downloaded archive - Next, rename the extracted directory:
$ mv etcd-v3.5.6-linux-amd64 etcd
Navigate into the directory:
$ cd etcd
Move all the binary files into the
/usr/local/bin
folder as:$ sudo mv etcd etcdctl etcdutl /usr/local/bin/
- Verify the installed binary is working on your system by checking the installed version:
$ etcd --version etcd Version: 3.5.6 Git SHA: cecbe35ce Go Version: go1.16.15 Go OS/Arch: linux/amd64
The command above should return the details about the installed etcd version. You can also check the installed versions of etcdctl and etcdutl utilities as shown:
$ etcdctl version Resulting output: etcdctl version: 3.5.6 API version: 3.5
To check the installed version for etcdutl, run:
$ etcdutl version etcdutl version: 3.5.6 API version: 3.5
Installing etcd on Ubuntu from Source code
In some cases, you may want to build a custom etcd binary from source.
- Start by installing the Go compiler and git on your system with the command:
$ sudo apt-get install golang git -y
Next, clone the etcd repository with the command:
$ git clone https://github.com/etcd-io/etcd.git
- Change into the
etcd
directory:$ cd etcd
- Next, run the build script with the command:
$ ./scripts/build.sh
- Once the build process is complete, you can find the binaries in the bin directory on the etcd main folder.
Add the path to the etcd binary to your system path as:$ export PATH="$PATH:`pwd`/bin"
- You can verify you have access to the etcd command by checking the version:
$ etcd --version
Managing ETCD Service
Depending on the installation method, you will need to start, stop, or restart the etcd service on your system. If you have the etcd database installed via the package manager, you can run the command provided below.
To start the etcd service:
$ sudo service etcd start
To stop the etcd service:
$ sudo service etcd stop
To restart the etcd service:
$ sudo service etcd restart
You can also check the service status with the command:
$ sudo service etcd status
Manual Etcd Service Setup
If you installed the etcd database manually or compilation, you will need to set up the etcd service manually. This section will walk you through setting up the etcd service on your machine.
Start by creating a configuration and data directory for the etcd service.
$ sudo mkdir -p /var/lib/etcd/default $ sudo mkdir /etc/etcd/
Change the ownership of the /var/lib/etcd
directory to your target user. In the command below, e set the ownership of the directory to the ubuntu
user:
$ sudo chown -R ubuntu:ubuntu /var/lib/etcd
Next, create an etcd unit file to allow you to manage the etcd daemon using the service command:
$ sudo touch /etc/systemd/system/etcd.service
Edit the file and add the following service configuration.
$ sudo vim /etc/system/system/etcd.service
Add the following data:
[Unit]
Description=etcd - highly-available key value store
Documentation=https://etcd.io/docs
Documentation=man:etcd
After=network.target
Wants=network-online.target
[Service]
Environment=DAEMON_ARGS=
Environment=ETCD_NAME=%H
Environment=ETCD_DATA_DIR=/var/lib/etcd/default
EnvironmentFile=-/etc/default/%p
Type=notify
User=ubuntu
PermissionsStartOnly=true
#ExecStart=/bin/sh -c "GOMAXPROCS=$(nproc) /usr/bin/etcd $DAEMON_ARGS"
ExecStart=/usr/bin/etcd $DAEMON_ARGS
Restart=on-abnormal
#RestartSec=10s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
Alias=etcd2.service
Replace the user with the target username you wish to run the etcd service. You can also change the location of the bin directory if you specify a custom directory during installation.
Next, reload the systemd daemon
$ sudo systemctl daemon-reload
Enable the service to start on boot:
$ sudo systemctl enable etcd.service
Next, start the etcd service with the systemd command:
$ sudo systemctl start etcd.service
Finally, check the service status:
$ sudo systemctl status etcd.service
The command above will output the service status.
Conclusion
This article gives a detailed guide on installing and setting up an etcd service on Ubuntu systems. We discussed three different installation methods: pre-built binary packages, building from source and using the package manager. We also covered how to manage the etcd service, whether installed via the package manager or manually. By following the steps outlined in this guide, you should be able to successfully install and set up an etcd cluster on your Ubuntu System.