I'm using capistrano to deploy a rails app, and it uses bundle install --deployment to put the gems in shared/bundle. I've put the appropriate platform :ruby and platform :jruby blocks in my gemfile, my question is if I switch rvm to jruby and then go to my app root directory and do another bundle install --deployment, will that mess with any of the existing gems there and replace them with jruby ones? Will I be able to switch back to mri and run the app like I always have? Will both platform's gems be in there, and then what about gems like nokogiri that have java versions, will that overwrite the mri version? Will I be able to just switch rvm versions and run the app via mri or jruby as I please at that point?
Turns out mri gems are installed in shared/bundle/ruby and jruby gems in /shared/bundle/jruby, so totally safe to switch to jruby, install your gems, and try it out
Related
i first installed jruby using the sudo apt-get install jruby command, which succeeded but it did gave me 1.5.6 version when i wanted a later version. So i uninstalled it and used rvm install jruby command and i was able to install jruby version 1.7.19 but after installing it, my ruby applications,which were funtioning right started producing errors complaining of missing gems like mysql2 gem missing,run bundle install. i run bundle install but nothing i did seemed to help, i was getting nowhere.
When i asked for the ruby version, i was receiving the jruby version instead, its lyk jruby over shadowing ruby,,,, So i decided to uninstall jruby, reinstall ruby and now ruby is functioning as well as before.
Can anyone help me with the ubuntu commands which can help me install jruby alongside ruby, so that both work well without any errors???
Am requesting for serious help please
I usually prefer rbenv over rvm for running multiple versions of Ruby on the same machine. Here is sample install/usage steps:
Install rbenv git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
Install ruby-build git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Modify your .bashrc echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Restart your shell
Install rubies. e.g. rbenv install jruby-1.7.20
Rehash (create new rbenv shims. You'll need to run this anytime you install a gem that adds a command) rbenv rehash
You can list the Ruby versions available to install with rbenv install -l
You can set the default global ruby version with rbenv global jruby-1.7.20.
You can also pass "system" instead of an installed Ruby if you want the default to be the OS installed version of Ruby.
You can change Ruby version on the fly with rbenv shell 1.9.3-p551
See here (https://github.com/sstephenson/rbenv#command-reference) for a lot more detail and documentation.
Edit: I was assuming you're using Ubuntu, hence the edit of .bashrc. If you're using another OS you may need to change that to .bash_profile
Thanks for that answer. I have also found out that it is soo possible to have jruby and ruby installed concurrently using rvm. After installing the various versions or languages say ruby and jruby, only the default language and version is running in the terminal as current so you have to run the command 'rvm list' to show you the various installed versions after which you run 'rvm use language-X.X.XX' say rvm use jruby-1.7.20.1 to make jruby-1.7.20.1 run as the current in that terminal.
You can also run another version in a different terminal concurrently but please note, you have to run the command rvm use every time you open up a new terminal, else you make that version default.
Any tutorials or blog are available to start with JRuby on Rails
which guide me to the installation and small JRuby on Rails application ?
I have gone through this Walkthroughs And Tutorials(https://github.com/jruby/jruby/wiki/WalkthroughsAndTutorials) link but most of the JRuby on Rails links are broken.
JRuby and Rails Installation
The easiest way to set up JRuby is using rvm. The following command installs rvm, the latest version if JRuby, and gets the latest version of rails:
$ curl -L https://get.rvm.io | bash -s stable --autolibs=3 --ruby=jruby --gems=rails
On Windows, you can download an installer which will set up JRuby for you. You then need to install rails by running the following command:
jruby -S gem install rails
Set up a Rails project
JRuby’s wiki page JRuby on Rails is a great collection of resources on the topic; it contains in particular a link to that good blog post: http://blog.rubyrockers.com/2011/03/rails3-application-jruby/
In a nutshell, to create a rails project based on JRuby, use the following command, replacing my_app with the name of your project:
rails new my_app -m https://www.jruby.org/templates/default.rb
Rails Development
Once your project is set up, any Rails 3 tutorial will do — it is Ruby after all!
Deployment
For deployment, have a look at:
“specific” solutions like Torquebox or Trinidad,
or warbler to package your app as a war and deploy in traditional Java app server (WebSphere, Weblogic, etc.).
Further Resources
Finally, it is also worth mentioning that Charles Nutter et al's book Using JRuby has a chapter dedicated to JRuby on Rails, and is an invaluable help in JRuby developments.
I have a Ruby/Rails devvelopment environment using rbenv, MRI Ruby (1.9.2-p290), rails 3.0.9, and SQLite3. I would like to port it to JRuby, but do it such that I don't have to do anything more than run "rbenv local jruby-1.6.4" and "rails server" in the root directory of the Rails application to use it with JRuby, and "rbenv local 1.9.2-p290" and "rails serer" to use it with MRI Ruby.
I am aware that the gems to access SQLite are different for Ruby versus JRuby, but how do you write the Gemfile such that the MRI-relevant gems are picked up when the Ruby is MRI, and the JRuby-relevant gems are picked up when the Ruby is JRuby?
I will also need to port it to MySQL instead of SQLite. Which gems do I need to use here for Ruby and JRuby?
For the record, I'm using Ubuntu 11.04, Ruby 1.9.2-p290, JRuby 1.6.4, and Rails 3.0.9 or 3.0.10.
We ported a large Rails application to JRuby last year and it was a surprising amount of work. Granted, part of it had to do with the app being rather badly written and having lots of legacy code, but still. In case you wonder: most of our problems came from gems we used, which then sometimes depended on e.g. FFI that didn't properly work with JRuby at that time. A port to Rubinius I did a little later seemed a lot less painful, but was abandoned in favor of staying with MRI.
For the Gemfile, there's a platform option you can use. Here's an example from the Bundler docs:
gem "weakling", :platforms => :jruby
gem "ruby-debug", :platforms => :mri_18
gem "nokogiri", :platforms => [:mri_18, :jruby]
It also has a block form:
platforms :jruby do
gem "foo"
end
Either form works well, since
All operations involving groups (bundle install, Bundler.setup,
Bundler.require) behave exactly the same as if any groups not matching
the current platform were explicitly excluded.
As a gem for MySQL I'd use the aptly named mysql, there seems to be a jdbc-mysql for JRuby.
I used the jruby zip executable to install 1.6.2, but it looks like they have released 1.6.4. How should I migrate from 1.6.2 to 1.6.4, should I have to re-install or is there a different command.
Mostly all you need to do is reinstall gems on the newly-unpacked JRuby (recommended), or migrate your existing gem installs by copying the lib/ruby/gems/* over to the new location. There's no automated update tool for JRuby itself right now.
Unpack new Jruby
export JRUBY_HOME=/path/to/jruby
export PATH=$PATH:$JRUBY_HOME/bin
Maybe even push the above to .bashrc
Add a list of required Gems to your Gemfile.
To reinstall Gems if needed the best way to do it is as follows
Jruby -S gem install bundler
Cd to /path/to/Gemfile
bundle install
I built my Rails 3 app using sqlite and now I'm trying to switch over to MySQL.
I created a new MySQL db, changed database.yml accordingly, and I added an older version of the mysql2 gem to my gemfile (gem 'mysql2', '< 0.3') which is supposed to play nicer with Rails 3.
I can start the dev server fine. When I visit a page, I get a Mysql2::Error (Table 'twitter_quiz_development.users' doesn't exist). Which is fine--I still need to add the schema to the new db. This is where I run into trouble:
rake db:schema:load returns this nasty error.
The solution found here did not work for me. gem pristine --all return this.
I'm running Ubuntu 11 if that helps.
It appears that the error has to do with JSON but I have no idea how to solve this. Thanks.
The issue(s) you are experiencing could be due to 3 things:
The version of Ruby you are using
The use of the SystemTimer gem with Ruby 1.9
The JSON gem
I've elaborated below...
The first thing I would suggest is to upgrade your version of Ruby 1.9. The latest stable is:
ruby 1.9.2p180 (2011-02-18 revision 30909)
I would highly recommend using Ruby Version Manager (RVM) to install and manage Rubies.
In terms of using the JSON gem, have a look at:
http://ruby.about.com/od/tasks/a/The-Json-Gem.htm
To quote:
On Ruby 1.8.7, you'll need to install a gem. However, in Ruby 1.9.2, the json gem is bundled with the core Ruby distribution. So, if you're using 1.9.2, you're probably all set. If you're on 1.8.7, you'll need to install a gem.
Before you install the JSON gem, first realize that this gem is distrubuted in two variants. Simply installing this gem with gem install json will install the C extension variant. This requires a C compiler to install, and may not be available or appropriate on all systems. Though if you can install this version, you should.
If you can't install the C extension version, you should gem install json_pure instead. This is the same gem implemented in pure Ruby. It should run everywhere that Ruby code runs, on all platforms and on a variety of interpreters. However, it's considerably slower than the C extension version.
Edit:
Looks like you should avoid using the SystemTimer gem with Ruby 1.9. See this for more info: http://isitruby19.com/systemtimer
To quote a comment made on that page by Phillipe:
I am the (co)-author of this gem. Short story : Using this gem in Ruby 1.9 is useless and does not make any sense!
System Timer is trying to work around some limitation of the "green thread" model used in Ruby 1.8 (MRI). See http://ph7spot.com/musings/system-timer for more details.
It is then irrelevant in a Ruby 1.9 which abandoned the green thread model and embraced native threads (kind of since there is still a global interpreter lock).
Cheers,
- Philippe
Your gem pristine --all looks like it errored out with the SystemTimer gem before it got to the json gem. Is that gem used in the Rails app in question?
Are you using RVM? If so, I'd manually remove the SystemTimer and json gems and their binaries (if any) from ~/.rvm/gems/ruby-whatever-version/ (in the gem and bin subdirectories).
Try to update to the latest version of the JSON gem (1.5.1) by adding this to your Gemfile:
gem "json", "1.5.1"
And then run bundle install to install SystemTimer and the later version of the json gem.