高木のブログ

CentOS 7.9 に Ruby 3.1.3 をインストールする

2023/04/03

問題

CentOS 7.9 に Ruby 3.1.3 をインストールしようとしたら、gcc のバージョンが古いみたいでインストールできなかった

$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ rbenv install 3.1.3
To follow progress, use 'tail -f /tmp/ruby-build.20230403202324.15642.log' or pass --verbose
Downloading ruby-3.1.3.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.3.tar.gz
Installing ruby-3.1.3...

BUILD FAILED (CentOS 7.9.2009 using ruby-build 20230330-2-gf2c3a7f)

Inspect or clean up the working tree at /tmp/ruby-build.20230403202324.15642.bk87LP
Results logged to /tmp/ruby-build.20230403202324.15642.log

Last 10 log lines:
compiling dmyext.c
translating probes probes.d
miniinit.c: トップレベル:
cc1: 警告: 認識できないコマンドラインオプション "-Wno-tautological-compare" です [デフォルトで有効]
cc1: 警告: 認識できないコマンドラインオプション "-Wno-self-assign" です [デフォルトで有効]
cc1: 警告: 認識できないコマンドラインオプション "-Wno-parentheses-equality" です [デフォルトで有効]
cc1: 警告: 認識できないコマンドラインオプション "-Wno-constant-logical-operand" です [デフォルトで有効]
cc1: 警告: 認識できないコマンドラインオプション "-Wno-cast-function-type" です [デフォルトで有効]
make: *** [miniinit.o] エラー 1
make: *** 未完了のジョブを待っています....

解決方法

gcc のバージョンを上げる

sudo yum install -y centos-release-scl-rh
sudo yum install -y llvm-toolset-7-clang
sudo yum install -y centos-release-scl
sudo yum install -y devtoolset-7-gcc.x86_64
sudo yum install -y devtoolset-7-gcc-c++.x86_64
scl enable devtoolset-7 bash
$ gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ rbenv install 3.1.3
To follow progress, use 'tail -f /tmp/ruby-build.20230403180741.23546.log' or pass --verbose
Downloading ruby-3.1.3.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.3.tar.gz
Installing ruby-3.1.3...
Installed ruby-3.1.3 to /home/vagrant/.rbenv/versions/3.1.3

無事インストールできた
詳しくは参考記事を

参考


SNS でシェアする


ytkg

Written by ytkg, Twitter, GitHub