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

rbenvでrubyのバージョンをあげたらrailsコマンドが動かなくなった

Posted at

現象

グローバルのRubyのバージョンは2.6だが、ローカルのディレクトリで、3.3.0を指定しました。

$rbenv local 3.3.0

その後、railsコマンドを実行すると、railsコマンドがありませんといったエラーが発生しました。

$rails new .
rbenv: rails: command not found
The `rails' command exists in these Ruby versions: 2.6.0

対応内容

現環境では、2つのRubyのバージョンが混在しているため、2つのフォルダが存在しています。

/home/vagrant/.rbenv/versions/2.6.0
/home/vagrant/.rbenv/versions/3.3.0

2.6.0のフォルダにはrailsファイルが存在するが、

$ls -l /home/vagrant/.rbenv/versions/2.6.0/bin | grep rails

3.3.0のフォルダにはrailsファイルが存在しません。

$ls -l /home/vagrant/.rbenv/versions/3.3.0/bin | grep rails

これが原因です。

Rubyのローカルが3.3.0になっていることを確認した上で、3.3.0で動くバージョンのrailsをインストールします。

$ruby -v
ruby 3.3.0
$gem install rails

インストール後に確認すると、railsファイルが見つかりました。

$ls -l /home/vagrant/.rbenv/versions/3.3.0/bin | grep rails

railsコマンドが実行できるようになりました。

$rails -v
Rails 8.0.2
0
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
0
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?