3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Amazon Linux 2023にrbenvでRuby3.2.2をインストールするときに詰まった点

Last updated at Posted at 2023-05-05

目的

EC2(Amazon Linux 2023)にrbenvでRubyをインストールするときに2点ほど詰まったので解決方法を備忘録として残す

環境

  • EC2のイメージ:Amazon Linux 2023
    • その他インスタンスのスペック等は無料枠で使える範囲
  • インストールしたRubyのバージョン:3.3.2

忙しい人向け

問題①
tmpfsの使用率が100%でエラー
解決策
インストール時にTMPDIRとして適当なディレクトリを指定する
TMPDIR="${PWD}/tmp" rbenv install 3.2.2

問題②
warning: It seems your ruby installation is missing psych (for YAML output).
解決策
libyaml-develをインストールする
sudo yum install libyaml-devel

やったこと

まずはEC2インスタンスにrbenvとruby-buildをインストール

[ec2-user@ip-172-31-5-99 ~]$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
[ec2-user@ip-172-31-5-99 ~]$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
[ec2-user@ip-172-31-5-99 ~]$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
[ec2-user@ip-172-31-5-99 ~]$ source .bash_profile
[ec2-user@ip-172-31-5-99 ~]$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

準備が整ったところでRubyをインストールしようとしたらエラー発生

[ec2-user@ip-172-31-5-99 ~]$ rbenv install 3.2.2
To follow progress, use 'tail -f /tmp/ruby-build.20230505012025.2228.log' or pass --verbose
Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...

BUILD FAILED (Amazon Linux 2023 using ruby-build 20230428)

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

Last 10 log lines:
compiling ossl_x509attr.c
compiling ossl_x509cert.c
compiling ossl_x509crl.c
/tmp/cckDPxFI.s: Assembler messages:
/tmp/cckDPxFI.s: Fatal error: ossl_x509crl.o: No space left on device
make[2]: *** [Makefile:326: ossl_x509crl.o] Error 1
make[2]: Leaving directory '/tmp/ruby-build.20230505012025.2228.yhZFfg/ruby-3.2.2/ext/openssl'
make[1]: *** [exts.mk:273: ext/openssl/all] Error 2
make[1]: Leaving directory '/tmp/ruby-build.20230505012025.2228.yhZFfg/ruby-3.2.2'
make: *** [uncommon.mk:331: build-ext] Error 2

どうやら/tmpのサイズが不足しているらしい

[ec2-user@ip-172-31-5-99 ~]$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs            4096       0      4096   0% /dev
tmpfs             486320       0    486320   0% /dev/shm
tmpfs             194532    2840    191692   2% /run
/dev/xvda1      31379436 2942712  28436724  10% /
tmpfs             486324  482792      3532 100% /tmp
tmpfs              97264       0     97264   0% /run/user/1000

調べてみたら、TMPDIRに大きな領域を指定してあげればOKとのこと

TMPDIR="${PWD}/tmp" rbenv install 3.2.2

参考:
https://qiita.com/hoken/items/db6c1c86bccf4ebf9f21
https://qiita.com/kanna/items/0851e136e12f1d52ff08

新たなエラー発生

上記で解決かと思われたが、新たなエラーが発生

[ec2-user@ip-172-31-5-99 ~]$ TMPDIR="${PWD}/tmp" rbenv install 3.2.2
To follow progress, use 'tail -f /home/ec2-user/tmp/ruby-build.20230505020042.24783.log' or pass --verbose
Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...

BUILD FAILED (Amazon Linux 2023 using ruby-build 20230428)

Inspect or clean up the working tree at /home/ec2-user/tmp/ruby-build.20230505020042.24783.tAuHn5
Results logged to /home/ec2-user/tmp/ruby-build.20230505020042.24783.log

Last 10 log lines:
transform_mjit_header: SKIPPED to transform: getlogin_r, pread64, pread, read, bsearch, fread_unlocked, fgets_unlocked, fread, fgets, vdprintf, dprintf, vfprintf, vprintf, printf, fprintf, getline, putchar_unlocked, putc_unlocked, fputc_unlocked, putchar, getchar_unlocked, getc_unlocked, fgetc_unlocked, getchar
ln -sf ../../../.ext/include/x86_64-linux/rb_mjit_min_header-3.2.2.h include/ruby-3.2.0/x86_64-linux/rb_mjit_min_header-3.2.2.h
Generating RDoc documentation
/home/ec2-user/tmp/ruby-build.20230505020042.24783.tAuHn5/ruby-3.2.2/lib/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
uh-oh! RDoc had a problem:
cannot load such file -- psych

run with --debug for full backtrace
make: *** [uncommon.mk:598: rdoc] Error 1

please install libyaml and reinstall your ruby.とのことなので素直に従ってみるも、、、

[ec2-user@ip-172-31-5-99 ~]$ sudo yum -y install libyaml
Last metadata expiration check: 1:04:13 ago on Fri May  5 00:55:10 2023.
Package libyaml-0.2.5-5.amzn2023.0.2.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

既にインストールされているとのこと。どういうこっちゃ。

ひたすらググる

色々調べてみたが、以下の記事で同様の問題を発見

libyaml-develをインストールすれば解決するらしいのでやってみる

[ec2-user@ip-172-31-5-99 ~]$ sudo yum install libyaml-devel

再度挑戦

[ec2-user@ip-172-31-5-99 ~]$ TMPDIR="${PWD}/tmp" rbenv install 3.2.2
To follow progress, use 'tail -f /home/ec2-user/tmp/ruby-build.20230505021355.36789.log' or pass --verbose
Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...
Installed ruby-3.2.2 to /home/ec2-user/.rbenv/versions/3.2.2


NOTE: to activate this Ruby version as the new default, run: rbenv global 3.2.2

できた!!(なお原因は理解できてない)

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?