Unable to Execute Rails console command Ruby - ruby-on-rails

/Users/parkerharris/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/completion.rb:10:in `require': dlopen(/Users/parkerharris/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
Referenced from: /Users/parkerharris/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
Reason: image not found - /Users/parkerharris/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
from /Users/parkerharris/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/completion.rb:10:in `<top (required)>'
from /Users/parkerharris/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:3:in `require'
from /Users/parkerharris/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:3:in `<top (required)>'
from /Users/parkerharris/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:138:in `require'
from /Users/parkerharris/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:138:in `require_command!'
from /Users/parkerharris/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/parkerharris/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/parkerharris/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
This is my error screen after trying to execute the command. I've tried to uninstall and reinstall readline and that did not help. I am just learning rails and do not 100% know what I am doing (just following a guide) so this type of error is past my understanding. Thanks!

Might not be related, but I had the same thing happen to me today.
I had a fully-functioning Ruby 2.3.1 working fine this morning. In my case, Ruby was compiled and installed by ruby-build and managed by rbenv.
At one point today I updated Homebrew with
brew cleanup --prune=30
brew update
brew upgrade
One of the formulae upgraded was readline 7.0:
$ brew info readline
...
/usr/local/Cellar/readline/7.0 (45 files, 2M)
Poured from bottle on 2016-10-05 at 08:09:22
Shortly afterwords I found that my readline support for Ruby had become completely broken. I saw errors just like yours:
/Users/mbrictson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/config/default.rb:151:in `require': dlopen(/Users/mbrictson/.rbenv/versions/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
Referenced from: /Users/mbrictson/.rbenv/versions/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
Reason: image not found - /Users/mbrictson/.rbenv/versions/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
from /Users/mbrictson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/config/default.rb:151:in `lazy_readline'
The solution was to completely delete my Ruby installation and recompile it:
rm -rf ~/.rbenv/versions/2.3.1
rbenv install 2.3.1
I know you are using rvm and not rbenv, but perhaps the solution in your case is similar: delete your Ruby installation and re-install it using rvm.

A really fast and quick solution is to add rb-readline to your Gemfile.
(In case the other solutions don't work and you want to move on until you have time to address the issue. I know it this is not ideal but it is a working solution.)
In the GemFile:
group :development do
gem 'rb-readline'
end
Now, just bundle install. I found this solution on Option 4 at
(https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X)
I hope it helps.

There's something wrong with your rvm, it doesn't seems to be related with rails. Please verify if it's installed properly.
Ensure that you've checked the rvm prerequisites on https://rvm.io/rvm/prerequisites
and that your install is working properly, e.g.
(from: https://rvm.io/rvm/install)
If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output rvm is a function as shown below.
$ type rvm | head -n 1
rvm is a function
Check on your mac if readline has been properly compiled, or try to do a clean install ruby-2.3.0 again
You can check on RVM regarding the package and autolibs on: https://rvm.io/packages/readline

I had similar issue. My Ruby was installed using HomeBrew. In my case I needed to uninstall Ruby; install/link libyaml; and then reinstall ruby.
brew uninstall ruby
brew link libyaml
brew install ruby

Same thing happened to me when I unwittingly ran rvm requirements after installing ruby 2.3.1.
rvm uninstall 2.3.1
rvm install 2.3.1
Above fixed it.

Running this from the command line worked for me:
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
from github

Related

can't run pod setup - cannot load such file -- cocoapods-core (LoadError)

I'm trying to install cocoapods so I can install a firebase plugin for my cordova app. I ran sudo gem install cocoapods and the gem was successfully installed. then when I tried to run pod setup it gave me some error, tried googling the solution, one of them was to uninstall cocoapods and run sudo gem update --system. did that, re-installed cocoapods, ran pod setup again, but now i'm getting a different error. this is what my terminal shows me after running pod setup:
Traceback (most recent call last):
10: from /Users/almiraputrisandy/.rvm/gems/ruby-head/bin/ruby_executable_hooks:24:in `<main>'
9: from /Users/almiraputrisandy/.rvm/gems/ruby-head/bin/ruby_executable_hooks:24:in `eval'
8: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/bin/pod:23:in `<main>'
7: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/bin/pod:23:in `load'
6: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/bin/pod:36:in `<top (required)>'
5: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
4: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
3: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods.rb:17:in `<top (required)>'
2: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods.rb:23:in `<module:Pod>'
1: from /Users/almiraputrisandy/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/almiraputrisandy/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- cocoapods-core (LoadError)
I can't seem to find the solution for this, so if anyone knows a solution, please help me! My Macbook's OS is HighSierra 10.13.6. Thank you in advance!
I have solved my problem by running the following:
$ sudo gem uninstall cocoapods-core cocoapods-downloader cocoapods
$ sudo gem install cocoapods
if you get a LoadError - cannot load such file -- cocoapods_deintegrate error after running pod install after running the 2 commands above, run this command to solve the problem:
$ sudo gem install cocoapods-deintegrate
Thank you to these two answers that helped me:
https://stackoverflow.com/a/32232410/8076737
https://github.com/CocoaPods/CocoaPods/issues/5111#issuecomment-204694892
It appears that Cocoapods doesn't like using Ruby installed via rvm or rbenv. If you're using these version managers for Ruby switch to the system Ruby
For rvm
rvm use system
For rbenv
rbenv global system
You'll probably want to switch back after you're done as system Ruby is terrible for development and if you're using rbenv/rvm you're likely doing Ruby development.
After switching to system Ruby pod setup worked fine for me.
edit: In general doing sudo anything is very bad practice. If you're required to do that your environment is setup wrong and while it may get you past this problem more bigger problems are heading your way.

After brew upgrade can't load bin/rails s

I'm working on rails5 project. Accidentally I typed brew upgrade (I supposed to uninstall imagemagick then install)
bin/rails c command is not working now.
enviroment:
Mac os 10.12
ruby 2.5.1p57 (2018-03-29 revision 63029)
[x86_64-darwin16]
Rails 5.1.6.1 , using gem 'mysql2', '0.4.10'
I tryed:
brew link readline --force
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
brew info readline
readline: stable 8.0.0 (bottled) [keg-only]
Library for command-line editing
/usr/local/Cellar/readline/8.0.0 (49 files, 1.5MB) *
Poured from bottle on 2019-02-15 at 17:16:19
but both still nothing changes, checked mysql.server start and it gives Starting MySQL.......... SUCCESS!
Also, checked mysql --version, got mysql Ver 8.0.15 for osx10.12 on x86_64 (Homebrew)
bin/rails s
Sorry, you can't use byebug without Readline. To solve this, you need
to rebuild Ruby with Readline support. If using Ubuntu, try `sudo apt-get
install libreadline-dev` and then reinstall your Ruby.
Traceback (most recent call last):
68: from bin/rails:6:in `<main>'
67: from bin/rails:6:in `require'
66: from
**dlopen(/Users/arthur/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-
darwin16/readline.bundle, 9): Library not loaded:
/usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
Referenced from:
/Users/arthur/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-
darwin16/readline.bundle
Reason: image not found -
/Users/arthur/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-
darwin16/readline.bundle**
Fixed problem.
Added 'rb-readline' gem file & bundle install.
https://github.com/deivid-rodriguez/byebug/issues/289

can't load pg gem even after installation

Sorry if the question is basic and forms of this has been asked. My sysadmin is out of the country so I'm stuck trying to figure this out. And none of the similar question has the exact situation (believe me I looked and have been banging my head against the wall for some time).
See below for my ruby/gem, which are all 1.9.3. Then upon running it somehow shows 1.9.1, not sure why. Anyway I've tried installing pg, the missing gem. It looked like it installed but re-running gives the same error message.
Please ask me any other information you feel is relevant.
rails#alpite:~/solr_indexer$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p551/bin/ruby
rails#alpite:~/solr_indexer$ which gem
/usr/local/rvm/rubies/ruby-1.9.3-p551/bin/gem
rails#alpite:~/solr_indexer$ ruby indexer.rb
/usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- pg (LoadError)
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/rails/solr_indexer/cfg.rb:2:in `'
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from indexer.rb:1:in `'
rails#alpite:~/solr_indexer$ gem install pg
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/local/rvm/gems/ruby-1.9.3-p551 directory.
rails#alpite:~/solr_indexer$ sudo gem install pg
[sudo] password for rails:
Sorry, try again.
[sudo] password for rails:
Building native extensions. This could take a while...
Successfully installed pg-0.17.1
1 gem installed
Installing ri documentation for pg-0.17.1...
Installing RDoc documentation for pg-0.17.1...
rails#alpite:~/solr_indexer$ ruby indexer.rb
/usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- pg (LoadError)
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/rails/solr_indexer/cfg.rb:2:in `'
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from indexer.rb:1:in `'
You're using a multi-user RVM installation to manage multiple Rubies. When using that, don't use sudo to install gems. The RVM installation page says:
Note: The Multi-User install instructions must be prefixed with the sudo command. However, once the install is complete, and the instructions to add users to the rvm group is followed, the use of either sudo or rvmsudo is no longer required. The sudo command is only to temporarily elevate privileges so the installer can complete its work. If you need to use sudo or rvmsudo after the install is complete, some part of the install directions were not properly followed. This usually is because people execute the install as root, rather than executing the installation instructions from a non-privileged user account.
I'd recommend reading that entire page as it has important information for using RVM with your environment.
The "Sudo" page is also good reading.

'security policies' error when trying to run bundle install

I have recently been having a lot of trouble with my rubies.
Now whenever I try and run bundle install on my projects I get the following error:
bundle install
/usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/bundler- 1.3.5/lib/bundler/rubygems_integration.rb:172:in `security_policies': uninitialized constant Gem::Security::Policies (NameError)
from /usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/cli.rb:175:in `<class:CLI>'
from /usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/cli.rb:6:in `<module:Bundler>'
from /usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/cli.rb:5:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/bin/bundle:18:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247#global/bin/bundle:23:in `load'
from /usr/local/rvm/gems/ruby-2.0.0-p247#global/bin/bundle:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
I have tried reinstalling rubies, I have tried rvm get head and gem update --system
I have also tried uninstalling and re-installing OpenSSL, through rvm package and brew install.
And I have tried completely imploding RVM and starting again, but none of this seems to work. This seemed to happen after I shifted to Mavericks.
Does anybody out there have an idea what might be happening? I have been at this for 3 days...
Edit:
I am having the same issue with all these rubies:
1.9.3
2.0.0-p195
2.0.0-p247
2.1.0-preview1
Assuming you're using brew...
Run brew doctor to check the current state and perform any steps it recommends.
Run rvm list and note which versions of ruby are installed. Remove the offending ruby version with rvm remove 2.0.x where 'x' is the minor revision you are working with, or run rvm remove 2.0 to remove them all.
Now upgrade to the latest rvm, rvm get stable.
Let rvm install dependencies automatically by running rvm autolibs enable. This will allow rvm to install whatever it needs during the ruby installation, including openssl. It will use brew, as I am assuming here, but will also use fink or macports if they are installed instead. In the past I have had problems with brew and macports both installed.
Install the latest ruby via rvm, rvm install 2.0.
Bundler should now work.
When running bundle install on a new rvm gemset running Ruby 2.0 and Rails 4.0 on OSX Mavericks, I was receiving the same error:
gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:172:in `security_policies': uninitialized constant Gem::Security::Policies (NameError)
Running 'brew install openssl', then 'rvm reinstall 2.0' worked for me.
Have you tried using the --trust-policy=[] option with bundle install?
To Apply the Rubygems security policy named policy, where policy is one of HighSecurity, MediumSecurity, LowSecurity, or NoSecurity.
More - http://bundler.io/v1.3/man/bundle-install.1.html

Cannot execute "rails console" due to an error with readline

I cannot execute rails console due to this error:
localhost:TwitterForZombies wiz$ rails c
/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `require': dlopen(/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib (LoadError)
Referenced from: /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
Reason: image not found - /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `require'
from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `<top (required)>'
from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `require'
from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I have installed readline via homebrew.
I'd like to keep using rbenv instead of rvm.
Thank you for reading my question.
I had the same issue recently with homebrew and libreadline.7.x.dylib / libreadline.6.x.dylib
I solved it by running:
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
source: https://github.com/rails/rails/issues/26658
Homebrew is great, but once in a while it doesn't play nice with some of the other moving parts.
A brew update && brew upgrade brought in libreadline.7.x.dylib while automatically removing libreadline.6.x.dylib, which ruby was still relying on.
There may be more clever ways to fix the problem, but brute force worked for me:
$ rbenv uninstall 2.3.1
$ rbenv install 2.3.1
$ cd /path/to/my/app
$ bundle
The above assumes the presence of rbenv's ruby-build and, of course, bundler; replace 2.3.1 with whatever version of ruby you are using.
Please note that similar problems can occur with different homebrew-managed libraries (see my own answer to this, for example)
I'm on OSX, ruby2.3.0, rails5. Adding gem 'rb-readline' to my Gemfile fixed this problem.
I got the same error with Ruby 2.1.0, and rails 4.0. After searching and trying a lot, finally it work well:) Here are what I did:
rvm cleanup all
rvm autolibs enable
rvm install 2.1.0
The other ways:
brew update
brew uninstall readline
brew install readline
The autolibs command will force RVM install all dependencies, so you don't need to worry about it.
Hope it's helpful.
As Sachin hinted, installing readline and then reinstalling ruby is the ideal approach - but the details are a bit different for rbenv. Given your file paths, I'm guessing you're on a Mac, so the following should help:
brew install readline ruby-build
env CONFIGURE_OPTS=--with-readline-dir=`brew --prefix readline` rbenv install 1.9.3-p286
This was taken from the ruby-build Wiki and a quick google search.
Using mac, El Captain version, it is possible to fix just by doing
rvm reinstall your_ruby_version
(like rvm reinstall ruby-2.3.1)
Hope this helps, good luck!
taken from github user #enderahmetyurt (this is the only solution that worked for me).
Solution: Add gem 'rb-readline' to your Gemfile in development group and bundle install. It's the easiest solution for silly "readline" errors.
try installing readline, and reinstall your ruby
https://rvm.io/packages/readline/

Resources