Capistrano Using Old Ruby Version - ruby

I'm trying to get Capistrano to work on my MacBook (OSX Mountain Lion) but am having a lot of difficulties. It started with it throwing an error:
cillosis:myapp macbook$ cap deploy
/Library/Ruby/Gems/1.8/gems/sshkit-1.2.0/lib/sshkit.rb:32: undefined method `require_relative' for main:Object (NoMethodError)
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/capistrano-3.0.1/lib/capistrano/all.rb:2
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/capistrano-3.0.1/bin/cap:2
from /usr/bin/cap:19:in `load'
from /usr/bin/cap:19
It seemed I had Ruby 1.8 installed and it doesn't work correctly with Capistrano (found this Googling around).
So I installed Ruby 2.0 using rvm. RVM starting throwing a bunch of errors so I got rid of it using rvm implode and found that the 2.0 version was still on my computer. I checked my $PATH and the locations it pointed at contained the Ruby 1.8. So I renamed that to *ruby_old* and copied the new ruby to that folder (/usr/bin). Then when I did a ruby -v it came back as version 2.0. So I thought, great, now we can finally run Capistrano.
Just to be sure, I did a gem update which came back as having updated the sshkit gem which was throwing the error before. So I go to deploy, and get the same exact error as I started with.
I know the deploy.rb script is correct because I use it all the time on another Mac.
TL;DR; After some fumbling, when I type ruby -v it comes back as using version 2.0 but when I do a cap deploy with Capistrano, it tries to use version 1.8 of ruby. How do I fix this?

The dumb, but simple way out would be to completely remove RVM and both ruby versions, then install again from scratch. I would recommend 1.9.x over 2.0 due to some gems not being up to speed yet, but that's up to you.
Another option would be to specify the ruby version in your gemfile (as heroku does it), then do a "bundle exec cap deploy". Again, no guarantees - but it might force capistrano to behave the way you want until you find a proper solution.

Related

Shotgun doesn't start after updating to Ruby 3.0.1

I'm trying to start Shotgun for a Sinatra app after having upgraded to Ruby 3.0.1, and get this:
$ shotgun
== Shotgun/Thin on http://127.0.0.1:9393/
/Users/me/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rack-2.2.3/lib/rack/handler/thin.rb:11:in `run': wrong number of arguments (given 2, expected 1) (ArgumentError)
from /Users/me/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/shotgun-0.9.2/bin/shotgun:156:in `<top (required)>'
from /Users/me/.rbenv/versions/3.0.1/bin/shotgun:23:in `load'
from /Users/me/.rbenv/versions/3.0.1/bin/shotgun:23:in `<main>'
Running gem list, I get:
shotgun (0.9.2)
What's going on? Thanks!
Ruby v3.0 introduces a breaking change, relating to keyword vs positional arguments.
The shotgun gem hasn't been updated for a long time; the latest version (0.9.2) was released in September 2016.
Looking at the gem in github, I see there's an open issue about this exact problem you've raised, and someone has already - helpfully - forked the project with a fix.
Unless the original author merges this fix and releases a new version of the gem, you'll need to use a forked version such as the above. For example, update your Gemfile to say:
gem 'shotgun', git: 'https://github.com/delonnewman/shotgun.git'
And then run bundle install.
There's also this open PR with the exact same fix, so you could equally use that fork instead.
... Or alternatively, stick to ruby 2.7 for now.

Rubocop using wrong version of Ruby - Fails

I've re-installed RVM, Ruby and all gems using rvm implode. When I run rubocop, I receive an error that it is using 2.5 (which I did not explicitly install but seems to come with RVM's Ruby 2.5.1)
Note the line I have highlighted with * * - this may be the issue?
$ which ruby
/Users/Will/.rvm/rubies/ruby-2.5.1/bin/ruby
$ rvm use 2.5.1
Using /Users/Will/.rvm/gems/ruby-2.5.1
$ rubocop
Inspecting 604 files
0 files inspected, no offenses detected
Unknown Ruby version: 2.5
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/processed_source.rb:131:in `parser_class’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/processed_source.rb:138:in `create_parser’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/processed_source.rb:94:in `parse’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/processed_source.rb:36:in `initialize’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/processed_source.rb:17:in `new’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/processed_source.rb:17:in `from_file’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:334:in `get_processed_source’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:110:in `block in file_offenses’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:121:in `file_offense_cache’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:109:in `file_offenses’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:100:in `process_file’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:78:in `block in each_inspected_file’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:75:in `each’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:75:in `reduce’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:75:in `each_inspected_file’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:67:in `inspect_files’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/runner.rb:39:in `run’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/cli.rb:82:in `execute_runner’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/lib/rubocop/cli.rb:28:in `run’
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/bin/rubocop:13:in `block in <top (required)>'
*/Users/Will/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/benchmark.rb:308:in `realtime’*
/Users/Will/.rvm/gems/ruby-2.5.1/gems/rubocop-0.49.1/bin/rubocop:12:in `<top (required)>'
/Users/Will/.rvm/gems/ruby-2.5.1/bin/rubocop:23:in `load’
/Users/Will/.rvm/gems/ruby-2.5.1/bin/rubocop:23:in `<main>'
/Users/Will/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval’
/Users/Will/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
Support for Ruby 2.5 was added to Rubocop in version 0.52.0. But you are using 0.49.1.
You need to update Rubocop to at least version 0.52.0 or even better update to the latest version (which is 0.63.1 as of today).
Depending on your setup you simply need to run bundle update rubocop or you might need to specify the desired version in your Gemfile first.
Found this thread when my VScode was looking for rubo cop gem installed within ruby 2.6 when it should have been looking within 2.7.
Not sure if this was the fix or if it was a number of other things but last thing I tried that work was setting the ruby version globally to 2.7
I use rbenv so was able to do rbenv global 2.7.4 and quit/restart vscode and the errors went away.

Padrino Project Generator Fails - Undefined Method `add_builtin_type'

I'm new to both Ruby and Sinatra/Padrino so I apologize if I'm missing something really simple.
I have Sinatra working fine, as I can build a very simple "hello" app and see it work.
I wanted to move on and generate a new Padrino project, but when I do this:
$ padrino g project foobar
I get this:
/Users/dave/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/ordered_hash.rb:3:in `<top (required)>': undefined method `add_builtin_type' for Psych:Module (NoMethodError)
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /Users/dave/.rvm/gems/ruby-2.1.5/gems/padrino-gen-0.12.4/lib/padrino-gen.rb:3:in `<top (required)>'
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/dave/.rvm/gems/ruby-2.1.5/gems/padrino-gen-0.12.4/bin/padrino-gen:12:in `<main>'
I have tried installing the Psych gem but this didn't change anything. I have no idea what to try next, or how to really interpret the error message. Any nudges in the right direction you can give me?
Bug reports show this may be an RVM issue.
I suggest changing from RVM to "ruby-install" and "chruby" because IMHO these are simpler, easier, and better at installing dependencies including psych and its libraries.
As joelparkerhenderson noted, the error message shows problems with gem files in the .rvm directory, suggesting some issue or conflict with rvm. Switching to system ruby solved the problem for me. I don't really need to use a specific version of ruby on this project, so that's a fine workaround for me.
I had this problem while using Ruby 2.1.5. After reading comments on here I realized it's not a RVM problem, but a ruby problem. I switched to 2.0.0-p576 and everything works. Psych must not be compatible with the new ruby versions.
However I don't understand how a different ruby version would cause this method to go missing. If anyone could explain that I would be grateful!
I ran into this using rbenv and padrino 0.13.0. Tried many versions of Ruby, including the system Ruby on OS X El Capitan, but found that that made no difference, so I'm now running the latest stable one (2.2.4).
Eventually I tried each version of the psych gem and found I could only get padrino g to work with an older version of the gem. Psych version 2.0.8 worked, while every newer version (up to the current 2.0.16) failed.
So: gem install psych -v=2.0.8 && gem uninstall psych -v '>= 2.0.9'
With me, after a lot of googling and reading various thread on S.O., it was only my rvm that was the problem. I was getting the rvm 'WARNING!' that rvm wasn't first in $PATH. You can check this with echo $PATH. Check out your ~/.bashrc see if there is anything like heroku toolbelt or linuxbrew, or whatever, loading themselves into your PATH at the FRONT i.e. PRE-PENDING your path, rather than APPENDING. This is indicated by something like export PATH="/usr/local/heroku/bin:$PATH". That sets heroku at the beginning of your PATH. Simply change it to export PATH="$PATH:/usr/local/heroku/bin".
I was trying to start a padrino project with activesupport, and this was causing problems. Changing to an earlier version of Ruby, as suggested in another thread, didn't cut it, because activesupport requires 2.2.0 or up.
Fixing my PATH, ensuring that rvm was initialized at the very beginning of the PATH, fixed my Padrino problem, and was able to initialize a project with the following command:
padrino g project sample_blog -t shoulda -e haml -c sass -s jquery -d activerecord -b
I know that's all a little off-tangent, but I think it's bound to help one or two people out there!
PS I'm using ruby 2.2.2p95 in this project folder.

Compass no longer working after ruby update

After installing RVM the other day I can no longer use compass watch as I could.
I've tried updating the system, installing compass again, as well as sass, all to no avail.
Here's the error I get in Terminal:
/Users/john/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/definition.rb:16:in `build': /Gemfile not found (Bundler::GemfileNotFound)
from /Users/john/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler.rb:148:in `definition'
from /Users/john/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
from /Users/john/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /Users/john/.rvm/gems/ruby-2.0.0-p247/gems/compass-0.12.2/bin/compass:26:in `<top (required)>'
from /Users/john/.rvm/gems/ruby-2.0.0-p247/bin/compass:23:in `load'
from /Users/john/.rvm/gems/ruby-2.0.0-p247/bin/compass:23:in `<main>'
from /Users/john/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
from /Users/john/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
I've attempted to use bundle update sass-rails per this question, but get the error Could not locate Gemfile
I've also tried to follow the advise here to no avail.
At this point I'm a bit lost. I'm brand new to the Ruby world as well as RVM, and am not the most proficient Terminal user to begin with.
Thanks for any assistance or insight-
/Gemfile not found was a bug in older version of rubygems-bundler gem, run:
rvm #global do gem update rubygems-bundler
and it should work fine
I don't have the answer as to how to fix the problem itself, but I did go through with simply removing it for the time being.
I used rvm implode to remove rvm from my machine per this post.
Everything worked fine after that. Unfortunately that'll delay my experimenting with the Ruby world for a little while longer as I don't have time to figure out how to have RVM without the complications it seemingly brought.
Best,

Error: Rack app won't run -- bundler/setup

I'm completely new to Ruby (and RoR) and I'm trying to set up a local environment to help work on a site. Ideally, I would work on it locally, and then commit the changes to github and push it further down the pipeline from there.
I'm on a brand new Macbook Pro running OSX Lion.
I have had much trouble trying to get it work:
Installed Xcode Command Line Tools and RVM couldn't install latest version of ruby because it failed to compile with LLVM (Lion default compiler)
compiled ruby using a special flag it asked me to use (forgot what it was), but then was having trouble with Postgres and Pow
Tried installing a standalone GCC to compile ruby correctly thinking it may solve the problem. Pow still gave me errors.
I have tried removing and installing everything I could think of, and still nothing. I stress: I'm a noob.
I finally found a script called railsready that sets up ruby and RoR for you (https://github.com/joshfng/railsready) which failed to recognize Xcode since Lion installs it into Applications (the script checked for it by looking for an Xcode .plist file in Library/Developer). The author helped be out by updating the code to look for gcc instead and it tried installing but failed because it couldn't write to my .bash_profile. I removed it and tried it again, and it worked.
I installed Pow so I can have it run on a custom domain (website.dev) and have multiple apps under different domains. Now it's giving me this error and I have no idea what it means or how to go about it.
I would really appreciate any help. Most ruby guys I talk to have no idea what this is about, and why Lion is so much trouble to set up on. They are on older (Snow Leopard) machines.
The Error
Your Rack app raised an exception when Pow tried to run it.
LoadError: no such file to load -- bundler/setup
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
~/Github/letsordernow/config/boot.rb:6
~/Github/letsordernow/config/application.rb:1:in `require'
~/Github/letsordernow/config/application.rb:1
~/Github/letsordernow/config/environment.rb:2:in `require'
~/Github/letsordernow/config/environment.rb:2
~/Github/letsordernow/config.ru:3:in `require'
~/Github/letsordernow/config.ru:3
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/builder.rb:4:in `instance_eval'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/builder.rb:4:in `initialize'
~/Github/letsordernow/config.ru:1:in `new'
~/Github/letsordernow/config.ru:1
Welcome to Ruby On Rails. :)
You're going to love the new Rails.app Kickstarter project by Yehuda Katz:
http://www.kickstarter.com/projects/1397300529/railsapp
My advice for now:
Standalone GCC is good. You're doing this right.
To use RVM with Lion and non-LLVM, read about compiling Ruby with clang: Can't install Ruby under Lion with RVM – GCC issues
In each of your Rails projects, run this which may clean up your Pow issues:
bundle install
Make sure each of your projects has a .rvmrc file pointing to the correct ruby version and gemset.
My two cents is to try to get up and running without RVM and Pow to start. These aren't needed and they have quirks with paths and glitches (IMHO). I personally prefer to use bundler to manage gemsets, and the rbenv tool and ruby-build tool for managing Ruby versions. See https://github.com/sstephenson/rbenv
Pow is nifty but tricky. It has a history of quirky setup (IMHO). My two cents is to get up and running with webrick first (i.e. make sure you can do "rails s" to start a local server) and then I personally like Apache and Passenger (or Thin). For Pow help on quirky setup see https://github.com/37signals/pow/issues/119

Resources