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

CentOS7下安装Ruby3.2.4的实施路径

一、CentOS版本

[user@zt ~]$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

二、先安装RVM

RVM是一个linux下的Ruby的多版本管理工具,可以维护多个Ruby版本,切换版本。对于开发Ruby应用程序比较友好。还有个优点就是不需要梯子,对于国内用户友好。

  1. 安装GPG的key,用于身份验证
$ gpg2 --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  1. 安装RVM最新稳定版本
$ \curl -sSL https://get.rvm.io | bash -s stable

三、安装Ruby的前置依赖

  1. 更新gcc版本,默认为4.8.5版本,最好升级到7以上版本,我们这里升级到了9版本,升级gcc版需要先更新yum源
$ yum install centos-release-scl -y

安装完成后在 /etc/yum.repos.d 目录下会出现 CentOS-SCLo-scl.repo 和 CentOS-SCLo-scl-rh.repo 两个文件,安装后源默认启用,但是坑也就是在这里被埋下了。CentOS 7 最晚在 2024年6月30后 停止更新维护,在此之前在 CentOS 7 可以通过 yum 直接安装 SCL 源基本都是可以正常使用的。这个时候需要更新源的地址:

$ vi /etc/yum.repos.d/CentOS-SCLo-scl.repo

修改此部分的baseurl为阿里云源

[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
$ vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

修改此部分的baseurl为阿里云源

[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

最后刷新缓存

yum repolist
yum clean all
yum makecache
  1. 正式升级gcc版本
yum install devtoolset-9-gcc* -y

显示如下即安装成功:

Installed:
  devtoolset-9-gcc.x86_64 0:9.3.1-2.2.el7 devtoolset-9-gcc-c++.x86_64 0:9.3.1-2.2.el7 devtoolset-9-gcc-gdb-plugin.x86_64 0:9.3.1-2.2.el7 devtoolset-9-gcc-gfortran.x86_64 0:9.3.1-2.2.el7 devtoolset-9-gcc-plugin-devel.x86_64 0:9.3.1-2.2.el7

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7     checkpolicy.x86_64 0:2.5-8.el7     devtoolset-9-binutils.x86_64 0:2.32-16.el7    devtoolset-9-libquadmath-devel.x86_64 0:9.3.1-2.2.el7    devtoolset-9-libstdc++-devel.x86_64 0:9.3.1-2.2.el7   
  devtoolset-9-runtime.x86_64 0:9.1-0.el7    gmp-devel.x86_64 1:6.0.0-15.el7    libgfortran5.x86_64 0:8.3.1-2.1.1.el7         libmpc-devel.x86_64 0:1.0.1-3.el7                        libquadmath.x86_64 0:4.8.5-44.el7                     
  libsemanage-python.x86_64 0:2.5-14.el7     mpfr-devel.x86_64 0:3.1.1-4.el7    policycoreutils-python.x86_64 0:2.5-34.el7    python-IPy.noarch 0:0.75-6.el7                           setools-libs.x86_64 0:3.3.8-4.el7                     

Complete!

启用新版gcc

scl enable devtoolset-9 bash

查看gcc版本:

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC) 

使当前的终端立即生效:

source /opt/rh/devtoolset-9/enable

四、安装指定版本的Ruby

CC=/opt/rh/devtoolset-9/root/usr/bin/gcc rvm install 3.2.4

显示如下即表示安装成功:

ruby-3.2.4 - #removing src/ruby-3.2.4..
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/7/x86_64/ruby-3.2.4.
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.2.4, this may take a while depending on your cpu(s)...
ruby-3.2.4 - #downloading ruby-3.2.4, this may take a while depending on your connection...
ruby-3.2.4 - #extracting ruby-3.2.4 to /usr/local/rvm/src/ruby-3.2.4.....
ruby-3.2.4 - #configuring..................................................................
ruby-3.2.4 - #post-configuration..
ruby-3.2.4 - #compiling...................................................................................................
ruby-3.2.4 - #installing.....................................
ruby-3.2.4 - #making binaries executable...
Installed rubygems 3.4.19 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
ruby-3.2.4 - #gemset created /usr/local/rvm/gems/ruby-3.2.4@global
ruby-3.2.4 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................
ruby-3.2.4 - #generating global wrappers........
ruby-3.2.4 - #gemset created /usr/local/rvm/gems/ruby-3.2.4
ruby-3.2.4 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-3.2.4 - #generating default wrappers........
ruby-3.2.4 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-3.2.4 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

查看RVM使用的当前Ruby版本

rvm list
=* ruby-3.2.4 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

http://www.kler.cn/news/308565.html

相关文章:

  • LeetCode_sql_day26(184,1549,1532,1831)
  • ubuntu系统服务器离线安装python包
  • 力扣(leetcode)每日一题 2848 与车相交的点
  • 7天速成前端 ------学习日志 (继苍穹外卖之后)
  • Spire.PDF for .NET【页面设置】演示:为 PDF 添加背景颜色或背景图像
  • python压缩图片的代码
  • 《锐捷AP 胖模式配置示例》
  • UiBot教程:实现复杂流程图的高效方法
  • C++学习笔记(21)
  • solidity-21-call_contract
  • 华为SMU02B1智能通信电源监控单元模块简介
  • 基于SpringBoot+Vue的养老院管理系统
  • 在Ubuntu中编译含有JSON的文件出现报错
  • 【前后端】大文件切片上传
  • 网络安全学习(一)初识kali
  • 【JavaEE初阶】多线程(5 单例模式 \ 阻塞队列)
  • 构建基于 Feign 的微服务:从 Eureka 到负载均衡的实践 --day05
  • 微信支付开发-前端api实现
  • 大模型笔记03--快速体验dify
  • HTTP的强制缓存和协商缓存有什么区别和联系?
  • 《使用 LangChain 进行大模型应用开发》学习笔记(三)
  • 行人动作行为识别系统源码分享
  • LLamaindex基本使用
  • MYSQL数据库基础篇——DDL
  • 第7篇:【系统分析师】计算机网络
  • openwrt wsdd模块介绍
  • C++(重载)
  • Skytower
  • 第二百三十五节 JPA教程 - JPA Lob列示例
  • k8s(kubernetes)的PV / PVC / StorageClass(理论+实践)