Sonic Master
Sonic Master

Reputation: 1246

Error using rails command on rails project

I am starting to learn about ruby on rails but somehow I got an issue calling rails in my project folder. When I call rails --version on a non project generated by rails it worked fine, but when I call inside the project, I get this error

❯ rails -v
/Users/mac/Devs/Rails/test/rails-test-api/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)
    from /Users/mac/Devs/Rails/test/rails-test-api/config/boot.rb:4:in `<top (required)>'
    from bin/rails:3:in `require_relative'
    from bin/rails:3:in `<main>'

Any rails command won't work inside my project folder.

I am running on Macbook Pro M1 Monterey 12.6 and already open my terminal in Rosetta. This is my spec

❯ rails -v
Rails 7.0.4

~
❯ ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]

~
❯ rails --version
Rails 7.0.4

~
❯ bundle version
Bundler version 2.3.23 (2022-10-05 commit 250d9d485d)

~
❯ gem --version
3.3.7

Any help would be appreciated, thanks!

--Edited

❯ rails --version
/Users/mac/Devs/Rails/test/rails-test-api/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)
    from /Users/mac/Devs/Rails/test/rails-test-api/config/boot.rb:4:in `<top (required)>'
    from bin/rails:3:in `require_relative'
    from bin/rails:3:in `<main>'
❯ rails --version
bin/rails:4:in `require': cannot load such file -- rails/commands (LoadError)
    from bin/rails:4:in `<main>'

--Edited I added gem 'bootsnap' into my Gemfile, run bundle install, I got Bundle complete! 4 Gemfile dependencies, 41 gems now installed. but I see no bootsnap installation there.

I already install bootsnap manually gem install bootsnap, succeed. But if i tried to bundle info bootsnap it will return Could not find gem 'bootsnap'.

Upvotes: 3

Views: 696

Answers (3)

Youssef Sobhy
Youssef Sobhy

Reputation: 343

Hope you're doing well - could you please give us more info? is it the same setup as this one? rails-api-playground (got this from your github repos), what's the output of the following commands?

which ruby

gem info bundler

bundle install

would be helpful if we can take a look at your Gemfile and Gemfile.lock as well. I believe it is a configuration issue as @kevin mentioned in the other answer.

will do my best to try and help you.

Upvotes: 1

kevinluo201
kevinluo201

Reputation: 1663

I guess it is pretty much a configuration problem. Bundler installation folder was not located properly. First, add bootsnap in the Gemfile. Try bundle install --path vendor/bundle to assign a installation location and then bundle exec rails -v

If this doesn't work, try to reinstall the bundler

Upvotes: 1

Taimoor Hassan
Taimoor Hassan

Reputation: 417

The error says cannot load such file -- bootsnap/setup (LoadError), which means you are having issue with the gem bootsnap, which main job is to run rails startup time.

If you want bootsnap, add gem bootsnap to your gemfile.

If you don't want it, remove the line require 'bootsnap/setup' in config/boot.rb.

Hope this helps!

Upvotes: 1

Related Questions