Complete Guide to Installing redis-cli Only on Linux Systems

Nov 20, 2025 · Programming · 23 views · 7.8

Keywords: redis-cli | Linux installation | Redis tools

Abstract: This article provides a comprehensive guide to installing only the redis-cli client on Linux systems, covering package manager installation of redis-tools, source code compilation for the latest version, and using nc as an alternative. It analyzes GLIBC version compatibility issues with direct binary copying and offers solutions for different Linux distributions.

Problem Background and Requirements Analysis

In distributed system development and maintenance, there is often a need to connect to remote Redis servers from local machines for debugging and management operations. Users typically want to install only the Redis command-line client redis-cli without the full Redis server components. This requirement is particularly common in development environments, continuous integration pipelines, and lightweight deployment scenarios.

Compatibility Issues with Direct Binary Copying

Many users attempt to copy the redis-cli binary file directly from a server with Redis installed to their local machine, but this approach often encounters dynamic library version mismatch issues. As shown in the error message: ./redis-cli: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by ./redis-cli), this indicates a discrepancy between the compilation environment and the runtime environment's GNU C library versions.

GLIBC is the core C library of Linux systems, and there are binary interface incompatibilities between different versions. When programs compiled in environments with newer GLIBC versions run on systems with older GLIBC versions, such version check failures occur. Solutions include using static linking during compilation or recompiling on the target system.

Installing redis-tools Using Package Manager

For Debian-based Linux distributions (such as Ubuntu), the simplest method is to install the redis-tools package. This package specifically contains the Redis command-line toolset, including redis-cli.

On Ubuntu 14.04 and similar versions, use the following command:

sudo apt-get install redis-tools

For Ubuntu 16.04 and newer versions, the command differs slightly:

sudo apt install redis-tools

The main advantage of this method is simplicity and speed, automatically handling dependencies and ensuring compatibility with the system environment. However, note that versions installed via package managers may not be the latest stable release; some Ubuntu versions might only provide Redis tools from the 2.8.x series, while the current stable version has progressed to the 7.x series.

Compiling and Installing Latest Version from Source

When the latest version of redis-cli is needed or the version provided by package managers is too old, compiling from source is the best option. Although this method involves more steps, it ensures access to the latest features and complete control over compilation options.

The complete compilation and installation process:

cd /tmp
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
sudo cp src/redis-cli /usr/local/bin/
sudo chmod 755 /usr/local/bin/redis-cli

The compilation process requires dependency on the development toolchain, including gcc, make, and the memory allocation library libjemalloc. On most modern Linux distributions, these dependencies are usually pre-installed or can be easily installed via package managers.

Advantages of compiling from source include: obtaining the latest version features, avoiding GLIBC version compatibility issues, and the ability to customize compilation options for performance optimization. Compilation time typically ranges from 1 to 3 minutes, depending on system performance.

Alternative Approach: Using netcat to Connect to Redis

In certain special circumstances where redis-cli cannot be installed, the system's built-in nc (netcat) tool can serve as a temporary alternative. Redis uses a simple text protocol, allowing commands to be sent directly via TCP connections.

Basic usage method:

nc -v redis.example.com 6379

After establishing the connection, Redis commands can be manually entered. For SSL encrypted connections:

nc -v --ssl redis.example.com 6380

While this method is feasible, it has significant limitations: lack of command completion, syntax checking, output formatting, and other convenient features provided by redis-cli, making it suitable only for simple debugging scenarios.

Special Considerations for Different Environments

In containerized environments, installation methods need corresponding adjustments. For Docker containers based on Alpine Linux, use:

apk --upgrade redis

In continuous integration environments like CircleCI, attention must be paid to user permission issues, typically requiring sudo to install compiled binaries into system paths.

Version Compatibility and API Changes

There are API changes in redis-cli between different major Redis versions, which require special attention in automated scripts. For example, the -u parameter introduced in Redis 4.0 for connection URLs is not available in earlier versions.

Version check command:

redis-cli --version

When writing cross-version compatible scripts, it's recommended to first check the redis-cli version before deciding which parameter format to use.

Best Practices Summary

Different installation strategies are recommended based on specific requirement scenarios: for quick deployment and simple usage, the redis-tools package is the best choice; for needing the latest features or specific versions, source compilation provides maximum flexibility; in extremely constrained environments, nc can serve as a temporary solution.

Regardless of the method used, it's advisable to verify the installation result:

redis-cli -h remote-redis-host -p 6379 ping

The correct response should be PONG, indicating that redis-cli has been correctly installed and can connect to the target Redis server.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.