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

 更新时间:2024年09月18日 09:43:43   作者:fredricen  
在CentOS 7系统上安装Ruby 3.2.4版本需要先安装RVM作为版本管理工具,安装过程涉及到安装GPG的key、RVM的最新稳定版本以及Ruby的前置依赖,下面给大家介绍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应用程序比较友好。还有个优点就是不需要梯子,对于国内用户友好。

安装GPG的key,用于身份验证

$ gpg2 --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

安装RVM最新稳定版本

$ \curl -sSL https://get.rvm.io | bash -s stable

三、安装Ruby的前置依赖

更新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

正式升级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

到此这篇关于CentOS7下安装Ruby3.2.4的实施路径的文章就介绍到这了,更多相关CentOS7安装Ruby3.2.4内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

最新评论