1
0

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.

Rubyのセットアップ(WSL)

Last updated at Posted at 2023-08-08

背景

Java,C#,VB.NET,Swift,Rust,TypeScript,Pythonなどは書いたり環境構築したことがあるが(Pythonはちょっと経験少ないが)、Rubyはまだまともに書いたことなかったので、Hello Worldくらいやってみようと思ったのでちょっとやってみる。
最近は環境構築はDockerのほうがいいかもだけども。

環境

  • WSL2(Ubuntu22.04)

手順

1. パッケージ更新して、rbenv を入れる。

apt-get install rbenvすると、ちょっと古いやつが落ちてくるので、git cloneする

$ sudo apt-get update
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv

2. パス設定 & 反映

$ echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
$ source ~/.bashrc

3. ruby-buildを入れる

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

4. libyaml-devを入れる

ruby3.2系をいれる際には別途インストールが必要になったらしいとのこと

$ sudo apt install libyaml-dev # ubuntuだと -dev をつけたパッケージ名らしい

5. rubyをいれる

$ rbenv install 3.2.2 # 2023.08.08の最新っぽいやつ
(補足) libyaml入れてないとエラーで落ちる
BUILD FAILED (Ubuntu 22.04 using ruby-build 20230717-11-g4d4678b)

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

Last 10 log lines:
*** Fix the problems, then remove these directories and try again if you want.
make[1]: Leaving directory '/tmp/ruby-build.20230808232212.1709.r0qEPi/ruby-3.2.2'
Generating RDoc documentation
/tmp/ruby-build.20230808232212.1709.r0qEPi/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

6. 一旦確認

$ rbenv local 3.2.2
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ echo "print \"Hello World\"" > hello.rb
$ ruby hello.rb
Hello World

Railsの設定

1. bundlerのインストール

$ sudo gem install bundler

2. 適当なディレクトリでinitして、Gemfileを修正

$ bundler init
Gemfile
gem "rails" # add this line

3. ruby-devをいれる

$ rbenv install 3.2.0-dev

4. install

これでrailsがインストールされる

$ bundle install

5. 適当なディレクトリでrailsのプロジェクト作成

$ rails new .

備考

けっこう環境構築ハマりどころが多いな、ruby。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?