【日常积累】指定ruby版本环境安装

背景说明

在redis的5.0版本之前,使用redis提供的redis-trib创建redis集群时还需要依赖ruby环境。当然有时候我们自已也需要安装指定ruby版本环境。下面是安装时的大致过程,以及过程中遇到的问题解决。我使用的环境是centos7,小版本差别应该不是很大,具体请自行测试。

安装

先安装ruby

bash 复制代码
#安装ruby环境
[root@k8s-m1 redis]# yum install ruby 
......
#gem是ruby的包管理工具,该命令可以安装ruby-redis依赖
[root@k8s-m1 redis]# gem install redis
Fetching: connection_pool-2.4.1.gem (100%)
ERROR:  Error installing redis:
connection_pool requires Ruby version >= 2.5.0.

可以看到在使用gem安装ruby-redis的依赖时,出现了报错。需要Ruby版本大于2.5.0。

安装rvm

先安装rvm,通过rvm来安装所需版本的ruby

bash 复制代码
# 确认自己环境的ruby版本确实低于2.5.0
[root@k8s-m1 ~]# ruby --version
ruby 2.0.0p648 (2015-12-16) [x86_64-linux] 

[root@k8s-m1 ~]# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: Signature made Sat 16 Jan 2021 02:46:22 AM CST using RSA key ID 39499BDB
gpg: Can't check signature: No public key
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.12.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

In case of further problems with validation please refer to https://rvm.io/rvm/security

# 上面在下载安装时有报错,在返回的结果中有说明尝试方法,我选用的最后一个
[root@k8s-m1 ~]# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
gpg: no ultimately trusted keys found
[root@k8s-m1 ~]# curl -sSL https://get.rvm.io | bash -s stable^C
[root@k8s-m1 ~]#  curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
gpg: key 39499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

导入相应的key后再进行尝试安装,可以正常安装

bash 复制代码
[root@k8s-m1 ~]# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
curl: (52) Empty reply from server

Could not download 'https://github.com/rvm/rvm/archive/1.29.12.tar.gz'.
  curl returned status '52'.

Downloading https://bitbucket.org/mpapis/rvm/get/1.29.12.tar.gz
Downloading https://bitbucket.org/mpapis/rvm/downloads/1.29.12.tar.gz.asc
gpg: Signature made Sat 16 Jan 2021 02:46:26 AM CST using RSA key ID 39499BDB
gpg: Good signature from "Piotr Kuczynski <piotr.kuczynski@gmail.com>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.12.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
  * Please do NOT forget to add your users to the rvm group.
     The installer no longer auto-adds root or users to the rvm group. Admins must do this.
     Also, please note that group memberships are ONLY evaluated at login time.
     This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM [0m
Please consider donating to our open collective to help us maintain RVM.

  Donate: https://opencollective.com/rvm/donate

[root@k8s-m1 ~]# source  /usr/local/rvm/scripts/rvm 

# 查看rvm库中已知的ruby版本
[root@k8s-m1 ~]# rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
ruby-head
......
# 此处省略了很多信息

安装指定ruby版本

从上可以看到支持安装很多版本的ruby版本,起初我直接安装的2.5.8版本,后续安装依赖时会报如下的错误。所以我重新安装了ruby3.0版本。各位不信邪的话可以自行尝试。

bash 复制代码
[root@k8s-m1 ~]# gem install redis
Fetching connection_pool-2.4.1.gem
Fetching redis-client-0.21.1.gem
Fetching redis-5.1.0.gem
Successfully installed connection_pool-2.4.1
ERROR:  Error installing redis:
        The last version of redis-client (>= 0.17.0) to support your Ruby & RubyGems was 0.19.1. Try installing it with `gem install redis-client -v 0.19.1` and then running the current command again
        redis-client requires Ruby version >= 2.6.0. The current ruby version is 2.5.8.224.

安装3.0版本

bash 复制代码
[root@k8s-m1 ~]# rvm install 3.0
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/7/x86_64/ruby-3.0.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-3.0.0, this may take a while depending on your cpu(s)...
ruby-3.0.0 - #downloading ruby-3.0.0, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 18.6M  100 18.6M    0     0   393k      0  0:00:48  0:00:48 --:--:-- 1215k
ruby-3.0.0 - #extracting ruby-3.0.0 to /usr/local/rvm/src/ruby-3.0.0.....
ruby-3.0.0 - #configuring.........................................................................
ruby-3.0.0 - #post-configuration..
ruby-3.0.0 - #compiling............................................................................................
ruby-3.0.0 - #installing....................................
ruby-3.0.0 - #making binaries executable...
Installed rubygems 3.2.3 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
ruby-3.0.0 - #gemset created /usr/local/rvm/gems/ruby-3.0.0@global
ruby-3.0.0 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................
ruby-3.0.0 - #generating global wrappers........
ruby-3.0.0 - #gemset created /usr/local/rvm/gems/ruby-3.0.0
ruby-3.0.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-3.0.0 - #generating default wrappers........
ruby-3.0.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-3.0.0 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

设置使用默认版本

bash 复制代码
# 使用一个ruby版本
[root@k8s-m1 ~]# rvm use 3.0
Using /usr/local/rvm/gems/ruby-3.0.0
# 可选择移除之前的版本
[root@k8s-m1 ~]# rvm remove 2.5.8
ruby-2.5.8 - #removing rubies/ruby-2.5.8..
ruby-2.5.8 - #removing gems....
ruby-2.5.8 - #removing aliases
ruby-2.5.8 - #removing wrappers....
ruby-2.5.8 - #removing environments....
Now using system ruby.
[root@k8s-m1 ~]# ruby --version
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
[root@k8s-m1 ~]# 

再次安装ruby-redis的相关依赖

bash 复制代码
[root@k8s-m1 ~]# gem install redis

Fetching redis-5.1.0.gem
Fetching connection_pool-2.4.1.gem
Fetching redis-client-0.21.1.gem
Successfully installed connection_pool-2.4.1
Successfully installed redis-client-0.21.1
Successfully installed redis-5.1.0
Parsing documentation for connection_pool-2.4.1
Installing ri documentation for connection_pool-2.4.1
Parsing documentation for redis-client-0.21.1
Installing ri documentation for redis-client-0.21.1
Parsing documentation for redis-5.1.0
Installing ri documentation for redis-5.1.0
Done installing documentation for connection_pool, redis-client, redis after 1 seconds
3 gems installed

以上就是指定版本的ruby安装,建议一般情况下,可以直接安装支持的最高版本。

相关推荐
来一杯龙舌兰5 小时前
【RabbitMQ】RabbitMQ保证消息不丢失的N种策略的思想总结
分布式·rabbitmq·ruby·持久化·ack·消息确认
明志-4 天前
RabbitMQ 工作模式使用案例之(发布订阅模式、路由模式、通配符模式)
分布式·rabbitmq·ruby
Agnoni6 天前
RabbitMQ消息队列的笔记
java·笔记·spring cloud·rabbitmq·ruby
飞的肖6 天前
RabbitMQ 安装、配置和使用介绍 使用前端js直接调用方式
开发语言·javascript·ruby
破局缘7 天前
apt文件问题ruby.list文件
开发语言·windows·ruby
Elastic 中国社区官方博客9 天前
如何将你的 Ruby 应用程序从 OpenSearch 迁移到 Elasticsearch
大数据·开发语言·数据库·后端·elasticsearch·搜索引擎·ruby
PGCCC10 天前
【PGCCC】 pg_query 6.0:使用 Postgres 自己的解析器解析、反解析和规范化 SQL 查询的 Ruby 库
数据库·sql·ruby
爱lv行10 天前
使用 rbenv 切换 Ruby 版本
开发语言·前端·ruby
信徒_13 天前
Rabbitmq 镜像队列
分布式·rabbitmq·ruby
姜西西_15 天前
RabbitMQ核心概念及工作流程 + AMQP
分布式·rabbitmq·ruby