1: ruby とruby on railsのインストール

参考:https://mebee.info/2021/04/10/post-33002/
その前に私はサブホストのベースとなるサブホスト(サブホストのテンプレート見たいな奴)を作り、サブホストを追加する際、このサブホストのクローンを作り、それの設定を変更して行くが、CentOS7の時はサブホストのUUIDも同じだったが、almalinux9では自動で違うUUDIが割り当てられている。但しそれ以外は同じものがあるので変更していく。先ずはホスト名
# gedit /etc/hostname
で開いたウィンドウに新しいホスト名を設定。次は固定IPアドレス
# nmcli device    ← デバイス名を調べる
DEVICE    TYPE          STATE                  CONNECTION
enp1s0   ethernet     接続済み                 enp1s0
lo            loopback    接続済み (外部)      lo
で固定アドレスを等を設定する

# nmcli c mod enp1s0 ipv4.method manual ipv4.addresses 192.168.XX.XX/24 ipv4.gateway 192.168.XX.XX ipv4.dns “192.168.XX.XX 8.8.8.8 8.8.4.4”
設定を反映させる
#
nmcli c up enp1s0

rubyは一般ユーザーで作業をするが、その前にgit等をインストールしておく
$ sudo dnf -y install git
実行しているユーザーのパスワードを求められるが、その後インストールが始まる
次に必要とされるパッケージのインストールだが、その前に開発系のツールが入っているalmalinux-crb(旧Powertools)リポジトリの有効化をする。
$ sudo gedit /etc/yum.repos.d/almalinux-crb.repo
                (Ver 8はalmalinux-powertools.repo  下記もcrbをpowertoolsに置き換えて)

[crb]
name=AlmaLinux $releasever – CRB
mirrorlist=https://mirrors.almalinux.org/mirrorlist/$releasever/crb
# baseurl=https://repo.almalinux.org/almalinux/$releasever/CRB/$basearch/os/
enabled=1           ← ここを0から1にする
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux-9
metadata_expire=86400
enabled_metadata=0
後略

rbenvのパッケージを自分のホームにcloneします。
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
入手したパッケージのパスを通し、初期化します。
$ echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bash_profile
$ ~/.rbenv/bin/rbenv init

# Please add the following line to your `~/.bash_profile’ file,
# then restart your terminal.

eval “$(rbenv init – bash)”

上のインフォメーションにあるようにbash_profileに追加し、反映させる
$ echo ‘eval “$(rbenv init -)”‘ >> ~/.bash_profile
$ exec $SHELL -l
rbenvのバージョンを確認します。

$ rbenv -v

rbenv 1.2.0-70-g4fec76f

rbenvのプラグイン であるruby-buildもインストールしておきます。こちらもgit cloneで入手し、追加されているか確認します。
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ ls ~/.rbenv/plugins/ruby-build/bin

rbenv-install rbenv-uninstall ruby-build

rubyに必要な依存パッケージをインストールしておきます。
$ sudo dnf install -y gcc openssl-devel readline-devel zlib-devel
インストールできるバージョンを確認
$ rbenv install -l

3.0.6
3.1.4
3.2.2
jruby-9.4.3.0
mruby-3.2.0
picoruby-3.0.0
truffleruby-23.0.0
truffleruby+graalvm-23.0.0

Only latest stable releases for each Ruby implementation are shown.
Use ‘rbenv install –list-all / -L’ to show all local versions.

上にあるように3.2.2が最新なので(時間がかかるよ)
$ rbenv install 3.2.2

前略
Last 10 log lines:
*** Fix the problems, then remove these directories and try again if you want.
make[1]: ディレクトリ ‘/tmp/ruby-build.20230803083833.28478.Co2UcH/ruby-3.2.2’ から出ます
Generating RDoc documentation
/tmp/ruby-build.20230803083833.28478.Co2UcH/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] エラー 1

あれーエラーが出ている。your ruby installation is missing psych と出ているので psychをインストールすればいいんだ。色々調べたらlibyaml-devel をインストールすれば良い見たいだが、念のためアップデートしておく
$ sudo dnf update (いっぱいアップデートがあった)
$ sudo dnf install libyaml-devel
あれー、そんなパッケージは無いといわれる。そんなバカな
よくよく調べるとalmalinux-crb.repoenabledが0になっていた(事情があって0にしていたのを忘れてた!!なのでenabled=1 にし、再度
$ sudo dnf install libyaml-devel
インストールされたので、再度
$ rbenv install 3.2.2  (またまたすごく時間がかかる)

To follow progress, use ‘tail -f /tmp/ruby-build.20230803090602.131953.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/fuji/.rbenv/versions/3.2.2

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

でバージョン指定はグローバルにするので
$ rbenv global 3.2.2
でgemのバージョンを確認
$ gem -v

3.4.10

gemをアップデートする
$ gem update –system

前略
RubyGems installed the following executables:
/home/ユーザー名/.rbenv/versions/3.2.2/bin/gem
/home/ユーザー名/.rbenv/versions/3.2.2/bin/bundle
/home/ユーザー名.rbenv/versions/3.2.2/bin/bundler

Ruby Interactive (ri) documentation was installed. ri is kind of like man
pages for Ruby libraries. You may access it like this:
ri Classname
ri Classname.class_method
ri Classname#instance_method
If you do not wish to install this documentation in the future, use the
–no-document flag, or set it as the default in your ~/.gemrc file. See
‘gem help env’ for details.

RubyGems system software updated

やっとrubyのインストールが出来た

ruby on railsのインストール(gemでできる)
$ gem install rails
いっぱいインストールされた。バージョンを確認
$ rails -v

Rails 7.0.6

 

フジマル について

1947年生れ、東京電機大学二部電気通信工学科卒、最後はスリランカ航空で営業だったのですが2018年に㈱インパック・ジャパンに再就職。趣味:登山、スキー、車いじり、コンピューター
カテゴリー: Ruby on railsに挑戦(almalinux9) パーマリンク

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください