Could not railties in mac os - ruby-on-rails

I had recently followed multiple blogs to completely wipe out rvm, rails and then reinstalled ruby 2.3.0 and rails 5. Made and app using it no issues. But the moment I opened a new terminal window in my machine it was not recognising rails at all as if it was only installed in that particular terminal.
So I just completed my work in that single terminal. Now when I restarted my laptop, I am unable to run the same app. I do not wish to reinstall everything again as I am sure this is a small configuration problem. Why is this happening?
The error message that I am getting now:
/Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'railties' (>= 0.a) among 30 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/sahil/.rvm/gems/ruby-2.3.1:/Users/sahil/.rvm/gems/ruby-2.3.1#global', execute `gem env` for more information
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /Users/sahil/.rbenv/versions/2.3.1/bin/rails:22:in `<main>'
I have already seen other similar questions where they ask to reinstall everything again which I do not want to do as it worked after installing but did not work on system restart.
Now I did gem install rails in one terminal and the app is working again, but if I try to open a new terminal and give the same command rails s, it gives me this error,
Ignoring byebug-9.0.5 because its extensions are not built. Try: gem pristine byebug --version 9.0.5
Ignoring debug_inspector-0.0.2 because its extensions are not built. Try: gem pristine debug_inspector --version 0.0.2
Ignoring nokogiri-1.6.8 because its extensions are not built. Try: gem pristine nokogiri --version 1.6.8
Ignoring byebug-9.0.5 because its extensions are not built. Try: gem pristine byebug --version 9.0.5
Ignoring debug_inspector-0.0.2 because its extensions are not built. Try: gem pristine debug_inspector --version 0.0.2
/Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': incompatible library version - /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/io-console-0.4.6/lib/io/console.bundle (fatal)
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/user_interaction.rb:9:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/config_file.rb:8:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/bundler-1.12.5/lib/bundler/rubygems_integration.rb:4:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/bundler-1.12.5/lib/bundler/shared_helpers.rb:6:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/bundler-1.12.5/lib/bundler/setup.rb:2:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /Users/sahil/Documents/work/Development/todoApp/config/boot.rb:3:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'

You mentioned that you reinstalled ruby 2.3.0 and Rails 5. However it seems rbenv is trying to load your project with ruby 2.3.1.
You should switch to ruby 2.3.0. I guess you should be able to do: rbenv local 2.3.0.
To avoid this from happening again though, you should add a .ruby-version dotfile to your project root and in the file only add 2.3.0.
Hope that works

Related

How to resolve gem dependencies when installing rbenv?

Recently I have installed rbenv and specified ruby to 2.3.1 and rails to 5.1.1 but I couldn't run my projects because I got:
Ignoring json-2.1.0 because its extensions are not built. Try: gem pristine json --version 2.1.0
Ignoring nokogiri-1.8.1 because its extensions are not built. Try: gem pristine nokogiri --version 1.8.1
Ignoring unf_ext-0.0.7.4 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.4
Ignoring yajl-ruby-1.3.1 because its extensions are not built. Try: gem pristine yajl-ruby --version 1.3.1
/var/lib/gems/2.3.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize': Could not find unf_ext-0.0.7.4 in any of the sources (Bundler::GemNotFound)
from /var/lib/gems/2.3.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `map!'
...
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/spring-2.0.2/bin/spring:49:in `<main>'
I ran:
bundle install
Installation passed successfully, but... Now I get:
/home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi.rb:6:in `require': incompatible library version - /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi_c.so (LoadError)
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi.rb:6:in `rescue in <top (required)>'
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi.rb:3:in `<top (required)>'
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify/native.rb:1:in `require'
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify/native.rb:1:in `<top (required)>'
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify.rb:1:in `require'
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify.rb:1:in `<top (required)>'
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/listen-3.0.8/lib
...
from /home/alex/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
And I have no idea how to resolve this. Any help is appreciated!
UPDATE 1:
Finally, I've found source of the evil bug - nevertheless, I specify Rails 5.1.1, when I run rails new app_name, it installs 5.1.6! And seems like it uses 5.1.6 gem dependencies... Still don't know how to resolve instead of upgrading to >= 5.1.6
Add the following line to your Gemfile.
gem 'rails', '5.1.1'
Run bundle install

can't find gem bundler Ruby

Using Mac OS 13, rbenv.
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
Rails 5.1.4
Bundler version 1.16.1
rbenv 1.1.1
I'm trying to start a new Rails application and then getting this:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem bundler (>= 0) (Gem::GemNotFoundException)
from /Library/Ruby/Gems/2.3.0/gems/railties-5.1.4/lib/rails/generators/app_base.rb:382:in `bundle_command'
from /Library/Ruby/Gems/2.3.0/gems/railties-5.1.4/lib/rails/generators/app_base.rb:416:in `run_bundle'
from (eval):1:in `run_bundle'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `block in invoke_all'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `each'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `map'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `invoke_all'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/group.rb:232:in `dispatch'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
from /Library/Ruby/Gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/application/application_command.rb:24:in `perform'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /Library/Ruby/Gems/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from /Library/Ruby/Gems/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from /Library/Ruby/Gems/2.3.0/gems/railties-5.1.4/lib/rails/cli.rb:16:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /Library/Ruby/Gems/2.3.0/gems/railties-5.1.4/exe/rails:9:in `<top (required)>'
from /usr/local/bin/rails:22:in `load'
from /usr/local/bin/rails:22:in `<main>'
As I understand it has something to do with a version of Ruby but I have no idea how to resolve the issue.
It looks like you may need to do a gem install bundler and get the bundler gem to get rails up and running.
STEP (1): install the bundler gem:
sudo gem install bundler
Once completed, you should get a message similar to this:
Fetching: bundler-1.16.1.gem (100%)
Successfully installed bundler-1.16.1
Parsing documentation for bundler-1.16.1
Installing ri documentation for bundler-1.16.1
Done installing documentation for bundler after 6 seconds
1 gem installed
STEP (2): try checking the bundler version:
bundle -v
You should get a version number like this:
Bundler version 1.16.1
STEP (3): now you can use bundle install:
bundle install
I hope my answer helps.

not able to login heroku

i was trying to login to heroku to push my app and until yesterday it was working but now it is giving me errors related to json version.
this is the log created after command heroku login
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:2275:in `check_version_conflict': can't activate json-1.8.2, already activated json-1.8.3 (Gem::LoadError)
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:1404:in `activate'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:89:in `block in require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:88:in `each'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:88:in `require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/heroku-3.99.1/lib/heroku/cli.rb:16:in `<top (required)>'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/heroku-3.99.1/bin/heroku:24:in `<top (required)>'
from c:/RailsInstaller/Ruby2.3.0/bin/heroku:22:in `load'
from c:/RailsInstaller/Ruby2.3.0/bin/heroku:22:in `<main>'
my ruby version is 2.3.3 and rails 5.0.3
Thank you
`check_version_conflict': can't activate json-1.8.2, already activated
json-1.8.3 (Gem::LoadError)
This is due to bundler trying to install json-1.8.2 when there is json-1.8.3 already installed. This is because bundler will use Gemfile.lock to install specified gem versions of gems.
You should do gem cleanup and followed by gem update json. This will update the json to latest version in Gemfile.lock and will resolve the problem.

Rails Console not running?

just started learning programming from Hartl's tutorial. I updated Ruby to 2.3.1 recently (using Rails 4.2.6) and I'm trying to run the console but I'm getting this error:
Carloss-MBP:sample_app carlosgrijalva$ rails console
/Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- rails/commands (LoadError)
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/carlosgrijalva/workspace/sample_app/bin/rails:9:in `<top (required)>'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/carlosgrijalva/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/carlosgrijalva/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Not entirely sure what that means. I notice that it's bringing up Ruby 2.3.0, did I not update Ruby properly? Should I just reinstall the gems?
After installing a new version of Ruby, you need to install your gems as well. If you are using bundler then just run:
# In your folder with `Gemfile` file.
bundle install
Regarding your ruby question you need to change your ruby version on your system using RVM or RBENV.
With RVM:
rvm use ruby-2.3.1 --default
With RBENV:
rbenv global 2.3.1
Then run:
bundle install

Ruby sqlite3 gem not found

I recently downloaded Crunchbang and am downloading a Ruby program. I installed Ruby:
apt-get install ruby
apt-get install rubygems
apt-get install sqlite3
When I run the file, I get:
root#crunchbang:/Pentest/NTLMRelay/ZackAttack# ruby zackattack.rb
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find sqlite3 (= 1.3.6) amongst [] (Gem::LoadError)
from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
from /Pentest/NTLMRelay/ZackAttack/lib/zfdb.rb:7:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Pentest/NTLMRelay/ZackAttack/clients/ews.rb:9:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Pentest/NTLMRelay/ZackAttack/lib/zfclient.rb:6:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Pentest/NTLMRelay/ZackAttack/lib/zfhttpd.rb:7:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from zackattack.rb:8:in `<main>'
I am completely at a loss. Help is appreciated/
You need to install ruby gem as well:
gem install sqlite3
If your program has a Gemfile, do:
gem install bundler
bundle install
Another advise, install ruby via RVM, it will save you from a number of headaches.
UPDATE:
Most likely you will also need the following package:
sudo apt-get install libsqlite3-ruby
You can also install the gem as follows using apt:
apt-get install ruby-sqlite3
or in my case:
apt-get install sqlite3-ruby
I would avoid installing Ruby using apt-get because you'll face a lot of problems (versions, gem management, etc) down the road. Use RVM instead.
Remove your apt-get installations (especially if your ruby -v returns something before 1.9) and then follow the instructions at http://rvm.io/rvm/install
RVM will allow you to install multiple Ruby versions and manage your gems more easily.
Once you're done with the rvm installation, do the following:
gem install sqlite3 -v 1.3.6
Once you have RVM running, things should become easier... Don't worry about the extra time you're spending in the beginning, it'll pay off :-)

Resources