Which gems is JRuby Rails using? - ruby-on-rails

If I startup my WEBrick server using
bundle exec jruby -S rails s
I'm getting following warning
c:/Program Files/jruby-1.6.7/lib/ruby/gems/1.8/gems/activesupport-
3.2.2.rc1/lib/active_support/core_ext/string/output_safety.rb:34
warning: regexp match /.../n against to UTF-8 string
Now, don't mind the warning, that's not part of my question. What is part of the question is why gems from 1.8 are being used when JRuby is set to used 1.9 mode?
$ bundle exec jruby -S rails s
=> Booting WEBrick
=> Rails 3.2.2.rc1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-03-05 13:41:02] INFO WEBrick 1.3.1
[2012-03-05 13:41:02] INFO ruby 1.9.2 (2012-02-22) [java]
[2012-03-05 13:41:02] INFO WEBrick::HTTPServer#start: pid=7624 port=3000
Version:
$ jruby -v
jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8)
(Java HotSpot(TM) Client VM 1.6.0_27) [Windows Vista-x86-java]

This got me curious too! (=
Irrespective of the mode you are using, the master repo for gem is in the
1.8 directory:
$ jruby -S gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.9
- RUBY VERSION: 1.8.7 (2011-10-25 patchlevel 330) [java]
- INSTALLATION DIRECTORY: C:/dev/jruby-1.6.5/lib/ruby/gems/1.8
...
- GEM PATHS:
- C:/dev/jruby-1.6.5/lib/ruby/gems/1.8
- C:/.gem/jruby/1.8
And with --1.9:
$ jruby --1.9 -S gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.9
- RUBY VERSION: 1.9.2 (2011-10-25 patchlevel 136) [java]
- INSTALLATION DIRECTORY: C:/dev/jruby-1.6.5/lib/ruby/gems/1.8
...
- GEM PATHS:
- C:/dev/jruby-1.6.5/lib/ruby/gems/1.8
- C:/.gem/jruby/1.9
The installation directory is set at JRuby compile time by the jruby.gem.home which is set by default to:
jruby.gem.home.1.8=lib/ruby/gems/1.8
(in default.build.properties in the JRuby codebase)
However, this shouldn't be a problem because when running in --1.9 mode, the LOAD_PATH contains 1.8.
$ jruby --1.9 -rpp -e 'pp $LOAD_PATH'
["C:/dev/jruby-1.6.5/lib/ruby/site_ruby/1.9",
"C:/dev/jruby-1.6.5/lib/ruby/site_ruby/shared",
"C:/dev/jruby-1.6.5/lib/ruby/site_ruby/1.8",
"C:/dev/jruby-1.6.5/lib/ruby/1.9"]

Related

Ruby On Rails executing with wrong version

I try to Run my new rails app using RubyMine, and it seems to use some wrong Ruby version and i can't figure out why!
I used rbenv to setup the environment
.ruby-version shows 3.0.2
/bin/zsh -c "bash -c 'env RBENV_VERSION=2.7.2 /usr/local/Cellar/rbenv/1.2.0/libexec/rbenv exec ruby /Users/ran/source/rails/MySite/bin/rails server -b 0.0.0.0 -p 3000 -e development'"
Your Ruby version is 2.7.2, but your Gemfile specified 3.0.2
ran#ran-mac MySite % ruby --version
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20]
ran#ran-mac MySite %
What's wrong? I can not understand where it takes this 2.7.2 from!
Thanks
Fixed it by changing the Ruby SDK, under Run\Debug Configurations to "Use other SDK: 3.0.2"

Weird rails error "permission denied: bin/rails" for old rails apps

I'm getting this error whenever I run rails (or any rails command)
_rails_command:2: permission denied: bin/rails
ONLY when i'm inside some old rails app directory.
In these directories bundle exec rails c command works but rails or even rails -v don't work.
Background:
I keep my coding workspace in dropbox folder.
Now I recently installed Manjaro and hence all the rails apps which I downloaded back from my previous OS I call them old rails app.
In Short:
Rails works fine everywhere except for old rails apps.
bundle exec rails c works fine though.
Ruby versions which I've tried:
2.0.0 (rvm), 2.1.1(rvm), 2.1.1 (system)
Gem Environment :
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.2
- RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/tat/.rvm/gems/ruby-2.0.0-p451#latest
- RUBY EXECUTABLE: /home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/ruby
- EXECUTABLE DIRECTORY: /home/tat/.rvm/gems/ruby-2.0.0-p451#latest/bin
- SPEC CACHE DIRECTORY: /home/tat/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/tat/.rvm/gems/ruby-2.0.0-p451#latest
- /home/tat/.rvm/gems/ruby-2.0.0-p451#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/tat/.rvm/gems/ruby-2.0.0-p451#latest/bin
- /home/tat/.rvm/gems/ruby-2.0.0-p451#global/bin
- /home/tat/.rvm/rubies/ruby-2.0.0-p451/bin
- /home/tat/bin
- /usr/local/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/bin
- /usr/bin/core_perl
- /home/tat/.rvm/bin
UPDATE:
Its working fine in bash, the problem seem to be with oh-my-zsh.
Here is my rvm-info (from zsh):
ruby-2.0.0-p451#latest:
system:
uname: "Linux tat-box 3.10.37-1-MANJARO #1 SMP Mon Apr 14 20:56:29 UTC 2014 x86_64 GNU/Linux"
system: "manjaro/0.8.9/x86_64"
bash: "/usr/bin/bash => GNU bash, version 4.3.8(1)-release (x86_64-unknown-linux-gnu)"
zsh: "/usr/bin/zsh => zsh 5.0.5 (x86_64-unknown-linux-gnu)"
rvm:
version: "rvm 1.25.23 (master) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]"
updated: "21 hours 33 minutes 15 seconds ago"
path: "/home/tat/.rvm"
ruby:
interpreter: "ruby"
version: "2.0.0p451"
date: "2014-02-24"
platform: "x86_64-linux"
patchlevel: "2014-02-24 revision 45167"
full_version: "ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]"
homes:
gem: "/home/tat/.rvm/gems/ruby-2.0.0-p451#latest"
ruby: "/home/tat/.rvm/rubies/ruby-2.0.0-p451"
binaries:
ruby: "/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/ruby"
irb: "/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/irb"
gem: "/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin/gem"
rake: "/home/tat/.rvm/gems/ruby-2.0.0-p451#latest/bin/rake"
environment:
PATH: "/home/tat/.rvm/gems/ruby-2.0.0-p451#latest/bin:/home/tat/.rvm/gems/ruby-2.0.0-p451#global/bin:/home/tat/.rvm/rubies/ruby-2.0.0-p451/bin:/home/tat/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/home/tat/.gem/ruby/2.1.0/bin:/home/tat/.rvm/bin"
GEM_HOME: "/home/tat/.rvm/gems/ruby-2.0.0-p451#latest"
GEM_PATH: "/home/tat/.rvm/gems/ruby-2.0.0-p451#latest:/home/tat/.rvm/gems/ruby-2.0.0-p451#global"
MY_RUBY_HOME: "/home/tat/.rvm/rubies/ruby-2.0.0-p451"
IRBRC: "/home/tat/.rvm/rubies/ruby-2.0.0-p451/.irbrc"
RUBYOPT: ""
gemset: "latest"
In the directory you mentioned is your rails in executable mode. If not you can apply
chmod u+x bin/rails
and make it executable.
Run
bundle exec rake rails:update:bin
It will update bin/rails and bin/rake files.
So what worked for me, anyone coming across this issue is to run
bundle exec rake app:update:bin
You'll be given a prompt asking if you want to overwrite? The options here are:
Y - yes (default one, just press Enter for it)
n - no (leave current file without changes)
a - all (apply all changes)
q - quit
d - diff
h - help
I chose a and it seemed to work ok.
I have this when I try to use a rails 4.0 version.
So when I try to put bundle exec first, like:
bundle exec rake db:migrate
or
bundle exec rails s
work's.
I had the same issue and here's what helped me.
Open ~/.zshrc and add this
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
The solution for me was:
bundle exec rake rails:update:bin
or just use:
For new rails versions:
bundle exec rake app:update:bin
For old rails versions:
bundle exec rake rails:update:bin

Ruby Rails webrick server using old version of ruby

ruby -v give me ruby-1.9.3-p194.
which ruby gives /home/ubuntu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
rails -v gives Rails 3.2.7
which rails gives /home/ubuntu/.rvm/gems/ruby-1.9.3-p194/bin/rails
"sudo bundle exec rails s" gives:
ubuntu#ip-10-117-73-5:~/ruby/users$ sudo bundle exec rails s
=> Booting WEBrick
=> Rails 3.2.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-09-11 20:13:08] INFO WEBrick 1.3.1
[2012-09-11 20:13:08] INFO ruby 1.8.7 (2011-06-30) [i686-linux]
[2012-09-11 20:13:08] INFO WEBrick::HTTPServer#start: pid=4240 port=3000
rvn info gives me:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [i686-linux]
- INSTALLATION DIRECTORY: /home/ubuntu/.rvm/gems/ruby-1.9.3-p194
- RUBY EXECUTABLE: /home/ubuntu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
- EXECUTABLE DIRECTORY: /home/ubuntu/.rvm/gems/ruby-1.9.3-p194/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/ubuntu/.rvm/gems/ruby-1.9.3-p194
- /home/ubuntu/.rvm/gems/ruby-1.9.3-p194#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
However when I run rails server I see below.
[2012-09-11 18:19:53] INFO ruby 1.8.7 (2011-06-30) [i686-linux]
I have no clue where this is coming from.
I have done "bundle install" and "bundle update" and a whole slew of things - it still is using the wrong ruby version. What do I need to do?
EDIT:
$PATH variable also only shows me 1.9.3 relevant information, how the heck is Webrick getting 1.8.7! If I remove that folder - it just doesn't start at all
Well seems what i needed was
rvmsudo rails server
I am just now learning when to use sudo and when not to - this was a painful experience.
Problem was that 1.8.7 was installed for sudo - while everything else was right for my user. But since I couldn't run 'rails server' by itself due to my previous incorrect installation, i had to use 'sudo rails server' - which ended up using the older ruby version.

How can I get control of gem installation locations?

Lots of confusion and difficulty related to gem installation. My gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- /Users/apple/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
The problem is one where I will add (eg) to environment.rb :
config.gem 'authlogic'
All good, now when I run
gem install authlogic
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /opt/local/lib/ruby/gems/1.8 directory.
running it with sudo is fine :
Dans-iMac-335:authlogic apple$ sudo rake gems:install
Password:
(in /Users/apple/Documents/projects/authlogic)
gem install authlogic
Successfully installed authlogic-2.1.6
1 gem installed
Installing ri documentation for authlogic-2.1.6...
Installing RDoc documentation for authlogic-2.1.6...
but running rake tasks throws an error :
Dans-iMac-335:authlogic apple$ rake db:migrate
(in /Users/apple/Documents/projects/authlogic)
Missing these required gems:
authlogic
You're running:
ruby 1.8.7.174 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
rubygems 1.3.5 at /Users/apple/.gem/ruby/1.8, /Library/Ruby/Gems/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
I can't see what the problem is. And I'm going out of my mind. The directory at the 'other' gems location :
Dans-iMac-335:authlogic apple$ ls /Users/apple/.gem/ruby/1.8/gems
actionmailer-2.2.2 activeresource-2.2.2 aws-s3-0.6.2 mysql-2.8.1 rails-2.2.2 xml-simple-1.0.12
actionpack-2.2.2 activeresource-2.3.3 builder-2.1.2 packet-0.1.15 rake-0.8.7
actionwebservice-1.2.3 activesupport-2.2.2 chronic-0.2.3 pg-0.8.0 rest-client-1.3.1
activerecord-2.2.2 activesupport-2.3.3 mime-types-1.16 rack-1.0.0 sqlite3-ruby-1.0.1
activerecord-2.3.5 activesupport-2.3.5 mongrel-1.1.5 rack-1.0.1 taps-0.2.26
This, I assume, is the default OSX rails system? The first location gives the much fuller set that represents my normal environment. Since my projects depend on many of these, and they aren't present in the other directory, this is verifiably the location that gems are being pulled from in my development environment:
Dans-iMac-335:authlogic apple$ ls /opt/local/lib/ruby/gems/1.8/gems
RedCloth-4.2.3 crack-0.1.8 mime-types-1.16 rack-1.1.0 sinatra-0.9.2
actionmailer-2.3.5 daemons-1.0.10 minitest-1.4.2 radiant-0.8.1 sinatra-1.0
actionmailer-2.3.8 faker-0.3.1 mogli-0.0.14 rails-2.2.2 spree-0.10.2
actionpack-2.3.5 fastthread-1.0.7 mongrel-1.1.5 rails-2.3.5 sqlite3-ruby-1.0.1
actionpack-2.3.8 gem_plugin-0.2.3 mutter-0.5.3 rails-2.3.8 sqlite3-ruby-1.2.5
activemerchant-1.5.1 google-geocode-1.2.1 mysql-2.8.1 rc-rest-3.0.0 state_machine-0.8.0
activerecord-2.3.8 hashie-0.4.0 net-scp-1.0.2 rest-client-1.0.3 stringex-1.0.3
activerecord-tableless-0.1.0 heroku-1.10.8 net-sftp-2.0.2 rest-client-1.6.1 taps-0.2.19
activeresource-2.3.5 highline-1.5.1 net-ssh-2.0.15 rmagick-2.13.1 taps-0.3.13
activeresource-2.3.8 hoe-2.3.3 net-ssh-gateway-1.0.1 ruby-hmac-0.4.0 thor-0.9.9
activesupport-2.3.8 hpricot-0.8.1 nokogiri-1.3.3 ruby-openid-2.1.7 treetop-1.4.8
authlogic-2.1.6 httparty-0.6.1 paperclip-2.3.1.1 rubyforge-2.0.2 whenever-0.3.7
authlogic-oid-1.0.4 json-1.1.9 passenger-2.2.5 rubyforge-2.0.4 will_paginate-2.3.11
aws-s3-0.6.2 json_pure-1.1.9 pg-0.8.0 rubygems-update-1.3.5 xml-simple-1.0.12
builder-2.1.2 json_pure-1.2.4 pg-0.9.0 rubygems-update-1.3.7
capistrano-2.5.9 launchy-0.3.3 polyglot-0.3.1 searchlogic-2.3.5
cgi_multipart_eof_fix-2.5.0 less-1.2.20 postgres-0.7.9.2008.01.28 sequel-3.0.0
configuration-1.1.0 libxml-ruby-1.1.3 rack-1.0.1 sequel-3.15.0
So, if the system uses this /opt/local/lib/ruby/gems/1.8/gems directory, why can't it see it when I call rake? And what can I do about it?
I don't see what the problem is, but have you tried running "gem list " to see what gems your system recognizes as having installed?
My solution was to change the #! line of rake.rb to point to the location of the ruby installation that has the gems.
From what I learned, when you're installing gems, rails takes account of the $PATH variable, but when loading the environment when rake is called, it doesn't. So rake doesn't know about those locations. The answer, then, was to direct rake's attention to the right location.

Rubygems. LoadError in Rails

Everytime I start my Rails applications I get LoadError with the following output.
On Rails 2.3.8:
no such file to load -- sqlite3/sqlite3_native
<internal:lib/rubygems/custom_require>:29:in `require'
On Rails 3.0.0:
no such file to load -- bundler
<internal:lib/rubygems/custom_require>:29:in `require'
I run the applications in the production mode on a development machine using Nginx + Passenger.
What is the reason of this issue? How can I solve it?
Thanks.
Debian GNU/Linux 5.0.6;
Ruby 1.9.2;
Rubygems 1.3.7;
Ruby on Rails 2.3.8, 3.0.0;
Nginx 0.8.50;
Passenger 2.2.15;
sqlite3-ruby 1.3.1;
bundler 1.0.0.rc.6.
Updated
All of my gems is installed by the unprivileged user in the local directory /home/<usernam>/.gem. If it helps, here's the gem env output:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
- INSTALLATION DIRECTORY: /home/<username>/.gem
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /home/<username>/.gem/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/<username>/.gem
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-ri --no-rdoc"
- :gemhome => "/home/<username>/.gem"
- :gempath => ["/home/<username>/.gem"]
- REMOTE SOURCES:
- http://rubygems.org/
Updated
I tackled with the problem. Its source was that I defined a custom gem path. That is I added to the ~/.gemrc file the following lines:
:gemhome: /home/<username>/.gem
:gempaths:
- /home/<username>/.gem
Thus all of my gems was placed in the specified directory but not the default one. For some reason Rubygems coundn't find it there and rose an exception.
When I removed that lines from the file the default paths was set for Rubygems and after I installed all the required gems and loaded my Rails applications all began to work.
Once again, the bug conditions are:
Nginx + Passenger;
The gempath is set to /home/<unprivileged_user>/.gem in ~/.gemrc;
An init.d script is creaded and added to the boot sequence (update-rc.d nginx defaults);
System is rebooted, server is started atomaticlally;
http://localhost/my_rails_app;
LoadError; no such file to load -- <gem_name>; <internal:lib/rubygems/custom_require>:29:in `require'.
Why can't Rubygems find gems in the custom location but can find them in default? That's the question.
I too had this problem when using RVM - I must have specified a gemset or something and not made it project specific. At any rate, read this rvm guide if you want to know the basics of RVM and try to specify a new gemset for your current folder / project, install a new rails gem to that gemset, and then use that gemset. For example, to create a new gemset for rails version 2.3.8:
$ rvm gemset create rails238
$ rvm ruby-1.8.7#rails238
$ gem install rails -v 2.3.8
Then if all went according to plan type rvm gemset use [gemsetName], or do rvm gemset list to see a list of installed gemsets, and to see if rails is working fine try rails -v and you should see rails 2.3.8
Check your system to locate where your rubies and gems are installed ( you can do this by "which ruby" and "which gem"). Usually, they're installed in the same folder (/usr/bin or /usr/local). If they are in different locations, there might be load error. Just a suggestion.

Resources