LoginSignup
11
8

More than 1 year has passed since last update.

Amazon Linux 2023のEC2にrubyをインストールすると/tmpディレクトリの容量不足でエラー

Last updated at Posted at 2023-03-21

タイトルの通り。自分用メモです。
みんな大好き無料枠有りのt2.micro等のインスタンスだと発生するのかなと。

https://github.com/rbenv/ruby-build/wiki#fedora
こちらのfedoraの項目を参考に追加のパッケージを入れておく

$ sudo dnf install -y gcc rust patch make bzip2 openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel

次に、この辺りの記事を参考にrbenvでrubyをインストールしようとする。
https://qiita.com/rubytomato@github/items/44eb173c0111283a418c
https://zenn.dev/mizko/scraps/af319aac43bbe7

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source .bash_profile

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install 3.1.2

すると以下のようなエラーがでる。

...
make[2]: ディレクトリ '/tmp/ruby-build.20230321153853.110799.qIoBYR/ruby-3.1.2/ext/pathname' に入ります
compiling pathname.c
/tmp/ccs7E0Gt.s: Assembler messages:
/tmp/ccs7E0Gt.s: Fatal error: can't write 3887 bytes to section .debug_str of pathname.o: 'デバイスに空き領域がありません'
/tmp/ccs7E0Gt.s: Fatal error: pathname.o: デバイスに空き領域がありません

ディスク容量を確認してみる。

$ df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         4.0M     0  4.0M    0% /dev
tmpfs            482M     0  482M    0% /dev/shm
tmpfs            193M  2.8M  190M    2% /run
/dev/xvda1        30G  4.3G   26G   15% /
tmpfs            482M  480M  2.6M  100% /tmp
tmpfs             97M     0   97M    0% /run/user/1000

はい、/tmpが100%。
この時点で軽く舌打ちしときます。

ちなみにruby-buildは/tmp配下にログ出力するみたいです。

神様、ありがとうございます!

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

これで通りました。

$ rbenv rehash
$ rbenv global 3.1.2
$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]

まとめ

これで行きましょう。

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source .bash_profile
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ TMPDIR="${PWD}/tmp" rbenv install 3.1.2
$ rbenv rehash
$ rbenv global 3.1.2
$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
11
8
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
11
8