Is using -S with JRuby recommended even when using a Ruby version manager? - jruby

Based on this page on the JRuby wiki and other resources I see the recommendation is
to always use jruby -S.
because
The -S parameter tells JRuby to use its version of the installed binary, as opposed to some other version (such as an MRI version) that might be on your PATH.
Using rbenv and rvm I've had issues when using -S with JRuby (see this question) and my understanding is that both those version managers solve the problem -S attempts to address.

You do not need to run the gem command with jruby -S gem if you are using a Ruby manager such as rbenv or rvm. Those tools manage your command path for you so that the correct Ruby runtime and the correct version of rubygems are used. Similar applies to the rake.

Related

Error installing "nokogiri" in a Ruby on Rails application?

I've been following along with the Lynda.com's Ruby on Rails course. I did everything just as mentioned inside the videos.
I am trying to run the rails server command, which should default to WEBrick, correct?
I run the command and it has an issue in the nokogiri.rb file and on line 29 where the error is happening this is what is read:
require 'nokogiri/nokogiri'
Which is what my command prompt is throwing up on when running the rails server command. Any idea what could be causing this? If so, what commands do I need to run to settle this? To me it sounds like something was missed when installing MySQL.
I am not sure what nokogiri is and why rails server won't run and points to that line of code.
The path to this file is (Wherever you installed the folder to)\lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2-x64-mingw32\lib
EDIT**: I have a chain of errors, like it goes from -long path-, from -longpath- etcetera. I tried installing the latest gem, and it wasn't successful. Is there a log file I can get to share with you guys to help figure out the issue.
nokogiri is a Ruby "gem" (library) for parsing XML and HTML.
Your Rails project should have a Gemfile which specifies the name and version of each gem needed to run the project. To install the gems listed in the gemfile:
bundle install
After that install completes successfully, Rails should be able to find the nokogiri gem.
Try this
$ sudo apt-get install libxslt-dev libxml2-dev zlib1g-dev
$ sudo gem install nokogiri -v '1.5.11'
According to \lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2-x64-mingw32\lib, which means that you are running it on Windows platform. You are using ruby 2.2.0.
I know that nokogiri conflicts with 2.2.* versions of ruby in Windows. I have already encountered this problem. I think it is because of mingw32.
You need to install 2.1.* version of Ruby in order to make Nokogiri work.

how can i install jruby alongside ruby

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.

Is Installing Jruby on Nitrious.io possible?

Does Nitrous.io support JRuby?
Installing it with RVM seems to attempt to run a sudo apt-get update, which it won't allow...
Thanks.
First you will need to update RVM.
rvm get head
From there you can install jruby:
rvm install jruby
Next, set RVM to use jruby.
rvm use jruby
Next, add jruby to your PATH.
export PATH=$PATH:/opt/jruby/bin
From there you should be able to check that jruby is working with the following command:
jruby --version
So, installing a jruby binary seems to work fine, but still cant figure out how to get RVM to do the install...
So, I just manually moved jruby into the .rvm folder...I put a copy of the binary in the .rvm/rubies directory, made a symlink from the binaries' "jruby" executable to a "ruby" executable in the .rvm/rubies bin folder, made related empty folders for jruby in the .rvm/gems directory for the version of jruby, and did "rvm jruby-1.7.8 do rvm gemset create" and now I can do "rvm use jruby"...things seem to work fine.
I have a bad feeling about this tho. But I always do when using RVM...
I don't know if it will actually require any additional packages (so this might not work), but you could try running rvm with --autolibs=0 so it doesn't attempt to install any packages; see https://rvm.io/rvm/autolibs for details.

Where to start for Jruby on rails?

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.

RVM, JRuby setting specific java environment

Ubuntu 10.04LTS
Netbeans 6.9.1 (with embedded JRuby 1.5.1)
JDK6u17 (installed in /opt)
GlassFish Gem 1.0.2
I am using a old JDK because of this bug: http://jira.codehaus.org/browse/JRUBY-4785
I want to install RVM and install another instance of JRuby. But i cant find any information how to set JRuby Java environment to JDK6u17(directory /opt).
I would be grateful for the help.
JRuby on default use system Java. So if i change "system" Java, JRuby will use that one.
I have figured two ways to set specific Java environment.
Set JAVA_HOME.
Here is a good one tutorial:
http://vietpad.sourceforge.net/javaonlinux.html
Update java setting from terminal(works only for JVM installed from apt-get or aptitude).
sudo update-alternatives --config java
That JRuby bug is marked as fixed for JRuby 1.6RC1, so you no longer need to use the old JDK.
I am using RVM and JRuby 1.6RC1 on Ubuntu 10.04 LTS just fine. There are instructions on my website for working with this version of Ubuntu, RVM and JRuby.
You don't need all the instructions, but some of the commands might help, if you get stuck.
http://www.scottlowe.eu/deploying-rails-3-with-jruby-daemonized-glass
(It does tell you how to get a modern JDK installed)