287

I have a Linux server with Redis installed and I want to connect to it via command line from my local Linux machine.

Is it possible to install redis-cli only (without redis-server and other tools)?

If I just copy redis-cli file to my local machine and run it, I have the following error:

./redis-cli: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by ./redis-cli)
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Oleg
  • 22,300
  • 9
  • 68
  • 84
  • 2
    Well, 1. it is not surprising that just copying the executable does not work: most likely you have different architecture and library versions, that cannot work. 2. you should consult the software management system your distribution provides and see what `redit` packages it provides. Then installing one of those shoudl only require a single click. You should _never_ do a wild installation of stuff into a Linux system if you can use the software management instead. – arkascha Feb 15 '14 at 08:47
  • @arkascha Thank you for your tip. I'm quite new to Linux so this information is very useful for me – Oleg Feb 15 '14 at 08:55
  • You mean you are a developer working under a Linux environment, but you never used your systems software management system? What distribution do you use? – arkascha Feb 15 '14 at 08:58
  • You might also be interested in a package called 'hiredis' which offers a minimalistic c client for redis. No ready-to-use cli client though. – arkascha Feb 15 '14 at 09:00
  • Well, actually I'm just playing with Redis. I'm on Ubuntu. I've installed Redis and it works fine. Then I installed Debian on VirtualBox, and now I'm trying to connect to Redis on Ubuntu from Debian virtual machine – Oleg Feb 15 '14 at 09:02
  • So how did you install `redis` on that ubuntu system? – arkascha Feb 15 '14 at 09:05
  • I've compiled the sources. I can do the same on Debian machine, but I'm just curious can I install just redis-cli without installing all redis components – Oleg Feb 15 '14 at 09:06
  • it seems that Debian doesn't support neither redis, nor redis-cli packages – Oleg Feb 15 '14 at 09:08
  • Why invest so much effort? Just pick the redis package in your software management and install it. That takes two minutes most and you can start using it. What is the advantage in doing all that by hand and ignoring all the advantages of cleanly installed packages? – arkascha Feb 15 '14 at 09:08
  • Debian does not offer redis packages? LOL. One more reasons not to use Debian. (sorry, could not resist). – arkascha Feb 15 '14 at 09:09
  • https://packages.debian.org/search?keywords=redis-server – arkascha Feb 15 '14 at 09:21
  • 2
    What about `git clone git@github.com:antirez/redis.git` then `cd src && make redis-cli`? – deltheil Feb 15 '14 at 11:52
  • I recommend the Docker solution, see my answer. Can be disposed at any time and your system's packages are untouched in the process. – Ondra Žižka Apr 19 '18 at 01:30

18 Answers18

516

Ubuntu (tested on 14.04) has package called redis-tools which contains redis-cli among other tools. To install it type:

sudo apt-get install redis-tools

Note that on Ubuntu 16.04+ the command is a little bit different:

sudo apt install redis-tools
Roman Pushkin
  • 5,639
  • 3
  • 40
  • 58
Иван Бишевац
  • 13,811
  • 21
  • 66
  • 93
137

Instead of redis-cli you can simply use nc!

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

Then submit the commands.

Balázs Németh
  • 6,222
  • 9
  • 45
  • 60
  • 19
    Try `nc -v redis.mydomain.com 6379` (or your custom port) – James111 Dec 30 '16 at 02:27
  • 8
    This is the best answer since it requires absolutely no dependencies or external tools. – pyrospade Mar 22 '17 at 15:08
  • 2
    is it possible to use this with a redis password? – Matt Bucci Apr 03 '17 at 22:45
  • 2
    You can also use `rlwrap nc -v redis.mydomain.com 6379` if you have `rlwrap` which lets you use keyboard shortcuts just as you would in a shell (e.g. cycle/search previous command, next word) – Prashanth Chandra Oct 10 '17 at 07:12
  • 3
    I can't find `--ssl` option for `nc`. Did you mean `ncat`? – hashlash Nov 19 '18 at 16:46
  • netcat - it depends on your OS what the binary exactly is. maybe it's called ncat. I don't know :( – Balázs Németh Nov 19 '18 at 20:30
  • @MattBucci You can do the following: `(printf "AUTH \r\n"; sleep 1) | nc -v redis.mydomain.com 6379` – Marc Shepherd Feb 01 '22 at 20:25
  • This can work, but it's tricky (especially with `--ssl`). There are different versions of `nc` out there -- so this isn't guaranteed to work with your version. The version that supports SSL is [provided by NMAP](https://packages.ubuntu.com/jammy/ncat). To provide a password after connecting, use the command: `AUTH (password)`. Another interesting point is that this works without [installing certificates](https://stackoverflow.com/a/73975504/86967). Hmm. – Brent Bradburn Aug 20 '23 at 22:23
69

From http://redis.io/topics/quickstart

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

With Docker I normally use https://registry.hub.docker.com/_/redis/. If I need to add redis-cli to an image I use the following snippet.

RUN cd /tmp &&\
    curl http://download.redis.io/redis-stable.tar.gz | tar xz &&\
    make -C redis-stable &&\
    cp redis-stable/src/redis-cli /usr/local/bin &&\
    rm -rf /tmp/redis-stable
Akhil
  • 912
  • 12
  • 23
Kevin Watson
  • 811
  • 1
  • 8
  • 9
36

To install 3.0 which is the latest stable version:

$ git clone http://github.com/antirez/redis.git 
$ cd redis && git checkout 3.0 
$ make redis-cli 

Optionally, you can put the compiled executable in your load path for convenience:

$ ln -s src/redis-cli /usr/local/bin/redis-cli
Agis
  • 32,639
  • 3
  • 73
  • 81
  • 4
    `git clone http://github.com/antirez/redis.git && cd redis && git checkout 2.8.6 && make redis-cli && cp src/redis-cli /usr/local/bin` - this works for me. – dhamu Sep 27 '14 at 18:00
  • tried to edit this. but here is a gist on how to do it now... https://gist.github.com/Artistan/d9288f8e12c4027096e66bd331d4e4fd – Artistan Dec 06 '17 at 14:43
36

In my case, I have to run some more steps to build it on RedHat or Centos.

# get system libraries
sudo yum install -y gcc wget

# get stable version and untar it
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable

# build dependencies too!
cd deps
make hiredis jemalloc linenoise lua geohash-int
cd ..

# compile it
make

# make it globally accesible
sudo cp src/redis-cli /usr/bin/
damoiser
  • 6,058
  • 3
  • 40
  • 66
22

For centOS, maybe can try following steps

cd /tmp
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
cp src/redis-cli /usr/local/bin/
chmod 755 /usr/local/bin/redis-cli
robert
  • 321
  • 2
  • 3
17

Using Docker, you may run this command to get Redis CLI:

docker run -it --rm redis:alpine redis-cli -h redis.mycompany.org -p 6379

where redis is the redis docker image from Docker Hub,
redis-cli is pre-installed in that image, and all after that are parameters to redis-cli:
-h is hostname to connect to,
-p is apparently the port to connect to.

You could also create an alias using the above command

alias redis-cli='docker run -it --rm --network=host redis:alpine redis-cli'

Which could be added to .bashrc if your using Bash

dariush
  • 3,191
  • 3
  • 24
  • 43
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
10

You can also use telnet instead

telnet redis-host 6379

And then issue the command, for example for monitoring

monitor
xelber
  • 4,197
  • 3
  • 25
  • 33
6

To expand on @Agis's answer, you can also install the Redis CLI by running

$ git clone -b v2.8.7 git@github.com:antirez/redis.git
$ make -C redis install redis-cli /usr/bin

This will build the Redis CLI and toss the binary into /usr/bin. To anyone who uses Docker, I've also built a Dockerfile that does this for you: https://github.com/bacongobbler/dockerfiles/blob/master/redis-cli/Dockerfile

bacongobbler
  • 867
  • 6
  • 14
6

For Amazon Linux

#sudo amazon-linux-extras install redis6
#redis-cli
ankursingh1000
  • 1,349
  • 1
  • 15
  • 21
5

2022 answer:

git clone https://github.com/redis/redis.git
cd redis/src/
make redis-cli
sudo cp redis-cli /usr/bin/redis-cli
redis-cli --version

worked for me.

Ivan Carcamo
  • 504
  • 4
  • 8
3

If you already have the node environment you can install it with npm

npm i -g redis-cli

Then run it with

rdcli

0

you may scp it from your redis machine if you have one, its just single binary. Or copy with nc if private network (this method is insecure):

redisclient: nc -l 8888 > /usr/local/bin/redis-cli
redisserver: cat /usr/local/bin/redis-cli | nc redisclient 8888
Zaur
  • 431
  • 4
  • 5
0

There are many way to install radis-cli. It comes with redis-tools and redis-server. Installing any of them will install redis-cli too. But it will also install other tools too. As you have redis-server installed somewhere and only interested to install redis-cli. To install install only redis-cli without other unnecessary tools follow below command

cd /tmp
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
cp src/redis-cli /usr/local/bin/
chmod 755 /usr/local/bin/redis-cli
  • 1
    Getting this error on copy command, any idea how to fix it cp src/redis-cli /usr/local/bin/ cp: cannot stat 'src/redis-cli': No such file or directory – Vipresh May 21 '20 at 17:25
0
# get system libraries
sudo yum install -y gcc wget

# get stable version and untar it
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make redis-cli

If the build fails / make command fails, then :

Removing all line with _Atomic from src/server.h and src/networking.c should makes the compile complete.

# make it globally accesible
sudo cp src/redis-cli /usr/local/bin/
0

for CentOS to get redis-cli without compiling it you can fetch Redis rpm from Epel repo and extract just ths tool. Here's step by step instruction

yum install -y jemalloc
yum install -y yum-utils
# NOTE - EPEL REPO MUST BE INSTALLED AND ENABLED
RPM_URL=$(yumdownloader --urls redis | tail -n1)
RPM=$(basename $RPM_URL)
mkdir /tmp/redis
cd /tmp/redis
wget $RPM_URL
rpm2cpio $RPM | cpio -idmv "./usr/bin/redis-cli"
mv ./usr/bin/redis-cli /usr/bin/redis-cli
rm -rf /tmp/redis
/usr/bin/redis-cli --version
-1

I made a simple pure-go solution, which is under development.

redis-cli: https://github.com/holys/redis-cli

Build once, and run everywhere. Fully portable.

Please feel free to have a try.

holys
  • 13,869
  • 15
  • 45
  • 50
  • Liked your solution, the last update is 3 years ago. Did you try building with the new go version, will it make any difference? – Govind Kailas Feb 26 '21 at 15:25
-2

There's a script that automatically download, build and install the latest redis-cli on Ubuntu 20.04 LTS.

To run it, copy and paste this on your terminal.

curl -sL "https://raw.githubusercontent.com/SecretX33/redis-cli/main/install_redis_cli.sh" | bash

Or wget, in case you don't have curl installed.

wget -qO - "https://raw.githubusercontent.com/SecretX33/redis-cli/main/install_redis_cli.sh" | bash

Feel free to look the source code: https://github.com/SecretX33/redis-cli

PS.: I'm the author of this script.

SecretX
  • 140
  • 1
  • 14
  • Some servers might not accept cURL queries. The sorts of apps that may be utilized with it may be restricted, which might be pretty problematic. Automated processes may be exceedingly challenging to employ on servers that do not even support curl. – Aymen Ragguem Mar 01 '23 at 09:06
  • This binary can be built once and cached in some internal Nexus server or something among these lines. My script cover the average use-case, which is not install redis-cli on a server, but on a normal workstation for the developer to use. If for some reason the situation you described happens, I hope the developer responsible for maintaining such servers knows the basics of Linux and Docker to be able to install the redis-cli using this script (either as-is or after some adaptation). – SecretX Apr 21 '23 at 23:53