文章目录
环境
阿里云:Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-77-generic x86_64)
安装方式
Redis安装方式有多种:一种是通过apt仓库;一种是下载源码,编译安装;如果使用Mac电脑,还可以通过homebrew安装。
一. apt库
命令:
sudo apt-get update
sudo apt-get install redis-server
这种安装方式已经设置好开机自启动,所以不用再去单独设置。
二. 源码的方式
下载Redis
官网下载链接 https://redis.io/download
选择最新的稳定版:
右键,获取下载链接,然后下载,解压,编译:
cd /opt
# 下载
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
# 解压
tar -xzf redis-6.2.5.tar.gz
cd redis-6.2.5
编译
# 编译
make
编译好,会输出下面的内容:
...
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory '/opt/redis-6.2.5/src'
手动安装
输入以下命令
make PREFIX=/opt/redis-6.2.5 install
这里多了一个关键字 PREFIX= ,这个关键字的作用是编译的时候用于指定程序存放的路径。
比如,指定了redis必须存放在/usr/local/redis目录。假设不添加该关键字Linux会将可执行文件存放在/usr/local/bin目录,库文件会存放在/usr/local/lib目录,配置文件会存放在/usr/local/etc目录,其他的资源文件会存放在usr/local/share目录。
这里指定号目录也方便后续的卸载,后续直接rm -rf /opt/redis-6.2.5
即可删除redis。
输出:
cd src && make install
make[1]: Entering directory '/opt/redis-6.2.5/src'
/bin/sh: 1: pkg-config: not found
CC Makefile.dep
/bin/sh: 1: pkg-config: not found
Hint: It's a good idea to run 'make test' ;)
INSTALL redis-server
INSTALL redis-benchmark
INSTALL redis-cli
make[1]: Leaving directory '/opt/redis-6.2.5/src'
注意
如果报错:
make: *** No rule to make target 'install'. Stop.
解决:
进入/o