简体   繁体   中英

Command 'rails server' not working or Rails server command not working

When I run "rails server" or "rails s" I got a error.

Hello I am learning Rails And I got error

This is error code

Traceback (most recent call last):
    52: from bin/rails:2:in `<main>'
    51: from bin/rails:2:in `load'
    50: from /home/wghu/Desktop/HelloRails/bin/spring:7:in `<top (required)>'
    49: from /home/wghu/Desktop/HelloRails/bin/spring:7:in `tap'
    48: from /home/wghu/Desktop/HelloRails/bin/spring:10:in `block in <top (required)>'
    47: from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in `require'
    46: from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in `require'
    45: from /var/lib/gems/2.7.0/gems/spring-3.0.0/lib/spring/binstub.rb:11:in `<top (required)>'
    44: from /var/lib/gems/2.7.0/gems/spring-3.0.0/lib/spring/binstub.rb:11:in `load'
    43: from /var/lib/gems/2.7.0/gems/spring-3.0.0/bin/spring:49:in `<top (required)>'
    42: from /var/lib/gems/2.7.0/gems/spring-3.0.0/lib/spring/client.rb:30:in `run'
    41: from /var/lib/gems/2.7.0/gems/spring-3.0.0/lib/spring/client/command.rb:7:in `call'
    40: from /var/lib/gems/2.7.0/gems/spring-3.0.0/lib/spring/client/rails.rb:28:in `call'
    39: from /var/lib/gems/2.7.0/gems/spring-3.0.0/lib/spring/client/rails.rb:28:in `load'
    38: from /home/wghu/Desktop/HelloRails/bin/rails:4:in `<top (required)>'
    37: from /home/wghu/Desktop/HelloRails/bin/rails:4:in `require_relative'
    36: from /home/wghu/Desktop/HelloRails/config/boot.rb:4:in `<top (required)>'
    35: from /home/wghu/Desktop/HelloRails/config/boot.rb:4:in `require'
    34: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/setup.rb:4:in `<top (required)>'
    33: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap.rb:112:in `default_setup'
    32: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap.rb:70:in `setup'
    31: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/compile_cache.rb:20:in `setup'
    30: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/compile_cache/yaml.rb:50:in `install!'
    29: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/compile_cache/yaml.rb:55:in `init!'
    28: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    27: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    26: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    25: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    24: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    23: from /usr/lib/ruby/2.7.0/yaml.rb:4:in `<main>'
    22: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    21: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    20: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    19: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    18: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    17: from /usr/lib/ruby/2.7.0/psych.rb:15:in `<main>'
    16: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    15: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    14: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    13: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    12: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    11: from /usr/lib/ruby/2.7.0/psych/nodes.rb:2:in `<main>'
    10: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
     9: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
     8: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
     7: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
     6: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
     5: from /usr/lib/ruby/2.7.0/psych/nodes/node.rb:2:in `<main>'
     4: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
     3: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
     2: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
     1: from /var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/var/lib/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': superclass mismatch for class StringIO (TypeError)

The command when I run before

rails g controller home index           

ubuntu version

21.10

My ruby version

ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]

Thanks for helping me

Your ruby version 2.7.4 and the folder rails s is using for the gems /var/lib/gems/2.7.0/ would indicate some kind of version mismatch to me.

Which ruby version is indicated in your Gemfile?

Have you installed rbenv or rvm ruby version managers?

If not i would advise you to do so as it makes Ruby version handling for each project (and globally) much easier.

You can check this article in gorails to install rbenv: Install Ruby On Rails on Ubuntu#rbenv

CAREFUL : If you choose to install rbenv keep in mind having multiple version managers is a BAD idea, so do not accidentally proceed with installing rvm . Those are not meant to coexist in the same system. Only follow up to this part:

rbenv install 3.0.2 (or whatever version you wish - preferably the one in your Gemfile)

rbenv global 3.0.2 (the same version you installed)

ruby -v

After these please rerun bundle install in the folder and try to run rails s again. Let us know how that went.

I started getting this error after updating my gems. I tried uninstalling ruby and all my gems, updating rvm, but for me the solution appeared to be updating rubygems.

gem update --system

Remove StringIO from your gem list by using below command. It works for me and I hope it will fix your issue as well.

gem uninstall stringio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM