Forem

kaede
kaede

Posted on

1

Rails 基礎 Part 00 -- asdf と ruby を動かす

Ruby 3.2.2 をインストール

MacOS Intel Core で作業する。


Ruby の安定版を公式サイトで確認

https://www.ruby-lang.org/en/downloads/

Ruby 公式で安定版を探す。
すると 2023-04 時点では 3.2.2 が安定版だと確認できた。


gitで 言語管理ツールの asdf をインストール

https://asdf-vm.com/#/core-manage-asdf

こちらの asdf 公式サイトと

https://dev.to/kaede_io/kotlin-ji-chu-part-10-mac-de-openjdk-to-javahome-wodong-kasu-17k2

java をインストールしたときの自分の記事を参考にする。

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3
Enter fullscreen mode Exit fullscreen mode

git で ~/.asdf を指定してダウンロードして

. "$HOME/.asdf/asdf.sh"
Enter fullscreen mode Exit fullscreen mode

シェル起動時に ./asdf/ の起動スクリプトを読み込むようにする。

asdf list 
No plugins installed
Enter fullscreen mode Exit fullscreen mode

シェルを再起動して、こうなれば成功。


❌ brew install asdf してはいけない理由

https://github.com/thoughtbot/dotfiles/issues/577#issuecomment-511902812

自分の環境で brew で入れた時、.asdf の設定ファイルがうまく生成できず、起動できなかった。

brew だとよく起こる issue のようだ。

インストール先の
/usr/local/Cellar/asdf/0.11.3
ここに作ってしまっていると予想する。

よって git で入れるべき。


asdf で ruby をインストールする

asdf plugin add ruby

Receiving objects: 100% (5082/5082), 1.13 MiB | 10.35 MiB/s, done.
Enter fullscreen mode Exit fullscreen mode

ruby を使えるようにする

asdf install ruby 3.2.2
Downloading ruby-build...
Installed ruby-3.2.2 to /Users/kaede0902/.asdf/installs/ruby/3.2.2
Enter fullscreen mode Exit fullscreen mode

ruby の 3.2.2 をインストール

asdf local ruby 3.2.2

cat .tool-versions 
ruby 3.2.2
Enter fullscreen mode Exit fullscreen mode

ruby の 3.2.2 がプロジェクトで動くように固定

ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin22]
re
ruby --version
ruby 3.2.2 
(2023-03-30 revision e51014f9c0) 
[x86_64-darwin22]
Enter fullscreen mode Exit fullscreen mode

シェルを再起動して最新の ruby が動くようにする。
3.2.2 が読まれているのを確認できた


ruby を対話シェルで試す

kaede0902@V source % irb                                                 
irb(main):001:0> print "hello ruby.\n"
hello ruby.
=> nil                                                                                 
irb(main)
Enter fullscreen mode Exit fullscreen mode

irb で Interactive RuBy が開く。
print が使える。
戻り値に nil が帰ってくる。null の代わり。特徴的だ。

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay