I was working on a project earlier today when suddenly my rails commands stopped working. I know that I must have introduced something that created an error but for the life of me I don't know what. The error that I get whenever I type any rails commands (for example, rails c, rails s, rails -v etc) is the following:
Traceback (most recent call last):
1: from /Users/mccoleman/.rvm/gems/ruby-2.5.1/bin/rails:23:in `<main>'
/Users/mccoleman/.rvm/gems/ruby-2.5.1/bin/rails:23:in `load': cannot load such file -- /Users/mccoleman/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/exe/rails (LoadError)
The following is my gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2', '>= 5.2.2.1'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
gem 'rspec'
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'rb-readline'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
I've tried searching for similar errors but haven't been able to find anything that looks similar. Any ideas why rails suddenly isn't working?
Take a look at RVM's gemset. Set a gemset for your project, use it, install and run bundle.
$ cd myproject
$ rvm create gemset mygemset
$ cat 'mygemset' > .ruby-gemset
$ cat 'ruby-2.5.1' > .ruby-version
$ cd .
$ gem install bundle
$ bundle
.ruby-version and .ruby-gemset allow RVM to set your Ruby version and gemset automatically when you cd to you project.
While I'm still not 100% sure what caused the error to occur, I was able to rectify it by uninstalling and then reinstalling rails.
Related
What error I'm getting
zsh: command not found: rspec
What I'm trying to do:
Run $ rspec inside my rails app
What I've done so far
Run $ bundle
Run $ rails generate rspec:install
Run $ gem install rspec
Run $ sudo gem install rspec
Run $ bundle update rspec-rails
Run $ bundle binstubs rspec-core
My Gemfile
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.4'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Below is the spec file I'm trying to execute using rspec
My setup
ruby 2.7.4p191
Rails 6.1.4
By the way I'm not having any problem running my spec using $ bundle exec rspec. I'm just curious how can I test my specs using the command $ rspec which most likely I will be using all throughout my career as a rails developer.
If you are working with bundler, most of the time you'll want to run gems under de bundled context; for rspec that is always true. You should either be using bundle exec (which you can alias to something shorter), or use the binstub with bin/rspec.
If you add ./bin to your PATH environment variable, you can run binstubs without needing to prefix with bin/; so you could do just rspec to call the binstub.
Prepending bundle exec tells the bundler to execute this command in context of the current bundle.
Try doing the following steps:-
gem install rubygems-bundler
gem regenerate_binstubs
Then try using rspec without bundle exec
I've been trying to deploy a Rails 6 application to Elastic Beanstalk and have been stuck with this Bundle Root error for over a day. I've read through everything I can find but nothing has worked so far.
[ERROR] An error occurred during execution of command [app-deploy] - [stage ruby application]. Stop running the command. Error: install dependencies in Gemfile failed with error Command /bin/sh -c bundle install --local failed with error Command timed out after 900 seconds. Stderr:Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
My gemfile:
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.3'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
gem 'sendgrid-ruby'
gem 'faker'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
gem 'will_paginate', '~> 3.1.0'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'sprockets', '~> 4.0'
gem 'devise'
gem 'bootstrap'
gem 'jquery-rails'
gem 'figaro'
gem 'rails-controller-testing'
gem 'validates_zipcode'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'minitest'
gem 'minitest-reporters'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', '>= 1.2016.7'
my .ebextension/fix_rails_6.config:
packages:
yum:
git: []
commands:
02_download_nodejs:
command: "curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -"
03_install_nodejs:
command: "yum -y install nodejs"
container_commands:
19_precompile:
command: "bundle exec rake assets:precompile"
And my environment properties:
BUNDLER_DEPLOYMENT_MODE true
BUNDLE_WITHOUT test:development
RACK_ENV production
RAILS_SKIP_ASSET_COMPILATION true
RAILS_SKIP_MIGRATION false
I'm guessing that you have an old, out-of-date Gemfile.lock on the deployed server which has incorrect versions of your Gems listed.
If this builds and runs locally, I would suggest ensuring that you distribute the Gemfile.lock file to your server along with the rest of the code and the Gemfile.
If that doesn't work, remove the Gemfile.lock from your deployed server and try again
I am attempting to install kaminari, but Rails cannot find it or a dependency (I've run into both - currently dependency):
∴ bundle exec rails g kaminari:config
Could not find i18n-1.8.4 in any of the sources
Run `bundle install` to install missing gems.
This is despite it being installed:
∴ bundle info i18n
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
* i18n (1.8.4)
Summary: New wave Internationalization support for Ruby
Homepage: https://github.com/ruby-i18n/i18n
Path: /Users/shawn/.rvm/gems/ruby-2.6.3#refstats/gems/i18n-1.8.4
I first attempted to delete Gemfile.lock. Same result. Then I deleted the refstats gemset and recreated it. Same result. Then I tried bundle install --force and got same result.
I've tried both gem 'kaminari', '~> 1.2' and gem 'kaminari' in my Gemfile.
Any suggestions?
EDIT:
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3', '~> 1.4'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'devise', '~> 4'
gem 'kaminari'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Edit 2:
∴ cat .ruby-version
ruby-2.6.3
I have no .ruby-gemset, but my console is reporting I'm using the right one:
12:36:50 shawn#macbook-pro:~/Documents/uga/refstats (git:master:547a0b4) ruby-2.6.3#refstats
∴
EDIT 3:
Well, the gremlin has disappeared, though I cannot say why. This is what I did:
1) Created new test rails app
2) Bundle install in new gemset
3) Added kaminari to Gemfile
4) Bundle install
5) Generated kaminari config successfully
6) Switch to non-working app, but forget to switch gemset, putting me in rvm with no gemset. Don't notice.
7) Bundle install
8) Notice things get installed, including kaminari. Notice I'm on wrong gemset.
9) Switch to correct gemset.
10) Bundle install (which installs nothing)
11) Generate kaminari config successfully
I really cannot say why it started working, unless installing to the rvm root had some effect. But that's what I did, and it's all working now. Thanks for the time.
Just because the gem is installed on your machine does not mean it is part of your bundle. bundle exec scopes the available gems to only what is included in your Gemfile and those gems dependencies. See if i18n for that version shows up when you run bundle show.
thank you for taking the time to read this. I'm extremely new to this, and am currently following a textbook for learning Rails, so apologies if I'm slow to pick up instruction. I'm currently on Chapter 5 of the Ruby on Rails tutorial (3rd edition), and part of this is my fault as I fiddled with something (I'm not exactly sure what) and now I get this error: I'm trying to install Bootstrap, and I was supposed to add a line of code in my gemfile. But now every time I try to run bundle install, I receive this error.
[!] There was an error parsing `Gemfile`: You cannot specify the same gem twice with different version requirements.
You specified: rails (= 4.2.2) and rails (~> 6.0.3, >= 6.0.3.1). Bundler cannot continue.
# from /home/ubuntu/environment/sample_app/Gemfile:10
# -------------------------------------------
# # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
> gem 'rails', '~> 6.0.3', '>= 6.0.3.1'
# # Use sqlite3 as the database for Active Record
# -------------------------------------------
I know it's probably something basic and obvious, but I would appreciate explicit instruction because I'm completely lost. Any and all help is appreciated! This is what my Gemfile looks like:
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bootstrap-sass', '3.2.0.0'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '> = 4.1.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
As the error message says, you have a couple of declarations for the rails gem.
Remove gem 'rails', '4.2.2' (at the top of the file, after source 'https://rubygems.org') and run bundle install (or just bundle).
Hope this helps!
Rails is defined twice on your Gemfile.
First on line 3 and the second on line 10. Just remove the first from line 3 and try bundle install again.
I'm starting a project on Rails 5 for the first time and I was curious why running 'rails s' when I was on Rails 4 worked fine, but now that I'm on Rails 5 I need to preface it with 'bundle exec' in order to run the command properly.
Below is my Gemfile. Again, everything works normally if I preface all my rails commands with. I'm just curious if anyone else experiencing this or if someone can give me some insight as to why this is happening?
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bootstrap', '~> 4.0.0.alpha3'
source 'https://rails-assets.org' do
gem 'rails-assets-tether', '>= 1.1.0'
end
gem "paperclip", "~> 5.0.0"
gem "browser"
# Use Capistrano for deployment
gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
It sounds like the rails command you have installed globally is rails 4 and it's the reason "it doesn't run properly" like you say. When you run bundle exec then it uses the rails commands from the current Gemfile, since you have rails 5 in your Gemfile then it works properly.
I'd recommend using either RVM or rbenv, I personally like RVM since it switches automatically to the gemset of the ruby version specified in my Gemfile.
Example, when I cd into the directory of my project I get a message like:
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too.
Using bundle exec guarantees that the program is run with the environment specified in the gemfile, which hopefully means it is the environment that the creators of the program want it to be run in, which hopefully means it should run correctly no matter what weird setup you have on your computer.
Reference: Use bundle exec rake or just rake?