LoginSignup
8
1

More than 5 years have passed since last update.

railsをインストールしたのにrailsコマンドが使えない!?原因は単純なことだった

Last updated at Posted at 2018-02-11

CentOSにrails環境を構築しようと思い、インストール等を済ませていざ、railsコマンドを使用したところ、「コマンドが見つかりません」となった。
何故だ。。。と思い、調べていくと以下のようなエラーが出ていた。

[root@localhost ~]# gem install rails
Fetching: concurrent-ruby-1.0.5.gem (100%)
Successfully installed concurrent-ruby-1.0.5
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.5.gem (100%)
Successfully installed tzinfo-1.2.5
Fetching: i18n-0.9.4.gem (100%)
Successfully installed i18n-0.9.4
Fetching: activesupport-5.1.4.gem (100%)
ERROR:  Error installing rails:
        activesupport requires Ruby version >= 2.2.2.

最後の行にERRORを発見。サポートしているrubyは、2.2.2だと言っているようだ。rubyのバージョンが2.2.0だったので、2.2.2に変えてみることに。

インストール対象を確認しインストールし直し
# rbenv install -l
# rbenv install -v 2.2.2
# rbenv rehash

バージョンを2.2.2へ切り替え
# rbenv global 2.2.2
バージョンを再確認すると2.2.2になった

[root@localhost ~]# ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [i686-linux]

railsを再度、インストール

[root@localhost ~]# gem install rails
Fetching: concurrent-ruby-1.0.5.gem (100%)
Successfully installed concurrent-ruby-1.0.5
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.5.gem (100%)
Successfully installed tzinfo-1.2.5
Fetching: i18n-0.9.4.gem (100%)
Successfully installed i18n-0.9.4
Fetching: activesupport-5.1.4.gem (100%)
Successfully installed activesupport-5.1.4
Fetching: mini_portile2-2.3.0.gem (100%)
・
・
・

今度は、ERRORにならず、インストールが進んだ。

railsコマンドを使ってみる

[root@localhost ~]# rails -v
Rails 5.1.4

よし!動いた。rubyとrailsのバージョンには注意が必要だ。

8
1
1

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