环境

  • 操作系统:Ubuntu 20.04

安装

方法1:直接安装

使用 apt install redis 直接安装:

➜  ~ sudo su -
➜  ~ apt install redis
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfwupdplugin1
Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  redis
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,064 B of archives.
After this operation, 63.5 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 redis all 5:5.0.7-2ubuntu0.1 [3,064 B]
Fetched 3,064 B in 0s (6,205 B/s) 
Selecting previously unselected package redis.
(Reading database ... 237205 files and directories currently installed.)
Preparing to unpack .../redis_5%3a5.0.7-2ubuntu0.1_all.deb ...
Unpacking redis (5:5.0.7-2ubuntu0.1) ...
Setting up redis (5:5.0.7-2ubuntu0.1) ...

缺点:Redis版本不是最新的。从上面的输出可见,Redis版本是5.0.7。

可通过 redis-cli -v 或者 redis-server -v 命令查看版本号。

➜  ~ redis-cli -v       
redis-cli 6.2.6
➜  ~ redis-server -v
Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=557672d61c1e18ba

方法2:先更新APT repository再安装

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

sudo apt-get update

sudo apt-get install redis

注:该方法来自Redis官网:https://redis.io/docs/getting-started/installation/install-redis-on-linux/

如果已经安装了旧版本,就会提示升级:

➜  ~ sudo apt-get install redis
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfwupdplugin1 libhiredis0.14 libjemalloc2 liblua5.1-0 lua-bitop lua-cjson
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  redis-server redis-tools
Suggested packages:
  ruby-redis
The following packages will be upgraded:
  redis redis-server redis-tools
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,189 kB of archives.
After this operation, 4,134 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Ign:1 https://packages.redis.io/deb focal/main amd64 redis all 6:6.2.6-3rl1~focal1
Get:2 https://packages.redis.io/deb focal/main amd64 redis-server amd64 6:6.2.6-3rl1~focal1 [82.5 kB]
Get:3 https://packages.redis.io/deb focal/main amd64 redis-tools amd64 6:6.2.6-3rl1~focal1 [1,067 kB]
Get:1 https://packages.redis.io/deb focal/main amd64 redis all 6:6.2.6-3rl1~focal1 [39.6 kB]                                                                                                              
Fetched 1,189 kB in 7s (180 kB/s)                                                                                                                                                                         
(Reading database ... 237210 files and directories currently installed.)
Preparing to unpack .../redis_6%3a6.2.6-3rl1~focal1_all.deb ...
Unpacking redis (6:6.2.6-3rl1~focal1) over (5:5.0.7-2ubuntu0.1) ...
Preparing to unpack .../redis-server_6%3a6.2.6-3rl1~focal1_amd64.deb ...
Unpacking redis-server (6:6.2.6-3rl1~focal1) over (5:5.0.7-2ubuntu0.1) ...
Preparing to unpack .../redis-tools_6%3a6.2.6-3rl1~focal1_amd64.deb ...
Unpacking redis-tools (6:6.2.6-3rl1~focal1) over (5:5.0.7-2ubuntu0.1) ...
Setting up redis-tools (6:6.2.6-3rl1~focal1) ...
Setting up redis-server (6:6.2.6-3rl1~focal1) ...
Installing new version of config file /etc/redis/redis.conf ...
Setting up redis (6:6.2.6-3rl1~focal1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.16) ...

升级后的版本是6.2.6。

方法3:源码安装

从Redis官网下载源码包。比如 https://download.redis.io/releases/redis-6.2.6.tar.gz 或者 https://download.redis.io/redis-stable.tar.gz

wget https://download.redis.io/releases/redis-6.2.6.tar.gz

解压:

tar -zxvf redis-6.2.6.tar.gz

解压后,生成 redis-6.2.6 目录。

进入该目录,运行 makemake install 命令:

cd redis-6.2.6/

make

make install

一阵刷屏之后,安装完毕。

注:该安装方法来自Redis官网:https://redis.io/docs/getting-started/installation/install-redis-from-source/

同样,其版本号也是6.2.6。

root@begetter1:~# redis-cli -v
redis-cli 6.2.6
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐