当前位置: 首页 > news >正文

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

背景说明

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

安装

先安装ruby

#安装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

# 确认自己环境的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 7D2BAF1CF37B13E2069D6956105BD0E739499BDBor 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后再进行尝试安装,可以正常安装

[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 serverCould 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版本。各位不信邪的话可以自行尝试。

[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 againredis-client requires Ruby version >= 2.6.0. The current ruby version is 2.5.8.224.

安装3.0版本

[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  CurrentDload  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

设置使用默认版本

# 使用一个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的相关依赖

[root@k8s-m1 ~]# gem install redisFetching 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安装,建议一般情况下,可以直接安装支持的最高版本。

http://www.lryc.cn/news/332036.html

相关文章:

  • SOC内部集成网络MAC外设+ PHY网络芯片方案:MII/RMII 接口与 MDIO 接口
  • 简单了解HTTP和HTTPS
  • 系列学习前端之第 9 章:一文搞懂 Node.js 和 nvm,掌握 npm
  • 超强命令行解析工具Apache Commons CLI
  • JAVAEE——多线程进阶,锁策略
  • 富文本编辑器Quill全套教程
  • Swift 代码注释的使用
  • 蓝桥杯—DS1302
  • nginx: 集群环境配置搭建
  • Linux:进程终止和等待
  • 一、next-auth 身份验证凭据-使用电子邮件和密码注册登录
  • 2.SpringBoot利用Thymeleaf实现页面的展示
  • devtool: ‘source-map‘ 和 devtool: ‘#source-map‘的区别
  • Flutter Boost 3
  • ElementUI响应式Layout布局xs,sm,md,lg,xl
  • 机器学习——典型的卷积神经网络
  • 速通数据结构与算法第四站 双链表
  • 51单片机学习笔记12 SPI接口 使用1302时钟
  • php编辑器 ide 主流编辑器的优缺点。phpstorm vscode atom 三者对比
  • 【动手学深度学习】深入浅出深度学习之RMSProp算法的设计与实现
  • 大转盘抽奖小程序源码
  • 数据结构(无图版)
  • 软件测试中的顶级测试覆盖率技术
  • vscode使用技巧
  • JSP
  • Mybatis--TypeHandler使用手册
  • 网络编程(TCP、UDP)
  • Python快速入门系列-7(Python Web开发与框架介绍)
  • 最长对称子串
  • 【大模型】大模型 CPU 推理之 llama.cpp