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
- I already add
gem "bootsnap", require: false
in myGemfile
, then I installed it but still get those error.
❯ 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>'
- I also already remove the bootsnap from my
Gemfile
and commentedrequire "bootsnap/setup"
in myboot.rb
. But it leads to another error
❯ 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'.
CodePudding user response:
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!
CodePudding user response:
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