I try to run a script on a LFS Batchsystem. The cluster offers an older version of ruby, so I had to install my gems and rvm locally on my account. Is there a way to run my local installed ruby version on a batch system? My script works fine on my account but not on LFS because mechanize depends on a newer ruby version.
Make sure you have rvm then
rvm use 1.9.3
or to set the default:
rvm use --default 1.9.3
And obviously, replace 1.9.3 with the version you want to use
Create .rvmrc file in your working directory in that you would mention which version of ruby you are going to you like:
rvm use 1.9.3#gemsetname --create
Now you can install all gems for this particular gemset.
I solved my problem with directly using the binary version and to define my local gem folder:
GEM_HOME=/home/my_name/.rvm/gems/ruby-2.0.0-p195/gems
/home/my_name/.rvm/bin/ruby-2.0.0-p195 my_script.rb
The other solutions do not work, because rvm is not available on the cluster.
Related
I have two scripts which require the same version of Ruby. However, each script also requires a DIFFERENT version of a gem (nokogiri). One of the scripts will run with both versions of nokogiri (1.6.2.1 and 1.6.1). However the other script will ONLY run with version 1.6.1; and if 1.6.2.1 is installed, the script will not execute normally.
I know how to install multiple versions of Ruby with rbenv. But is it possible to install multiple instances of the SAME version of Ruby (2.1.2)? If so, how?
Make a local copy of a ruby-installer definition file using a custom name.
$ cp ~/.rbenv/plugins/ruby-build/share/ruby-build/2.1.5 2.1.5-nokogiri161
Install this as a custom definition file, no edits required.
$ rbenv install ./2.1.5-nokogiri161
Now you have a ruby version with a custom name and you can install custom gems on it.
$ rbenv shell 2.1.5-nokogiri161
$ gem install nokogiri -v 1.6.1
This is also useful for installing ruby versions with custom build flags. For example, a debug build with no compiler optimizations.
$ cp ~/.rbenv/plugins/ruby-build/share/ruby-build/2.1.5 2.1.5-debug
$ RUBY_CONFIGURE_OPTS="optflags=-O0" rbenv install ./2.1.5-debug
$ rbenv shell 2.1.5-debug
1) Use rvm instead of rbenv, and using it feature called 'gemsets' you could use different versions of gems for one version of ruby
rvm 2.1.1
rvm gemset create first second
rvm 2.1.1#first
gem install nokogiri -v 1.6.1
rvm 2.1.1#second
gem install nokogiri -v 1.6.2
2) or you can use bundler
gem install bundler
/dir_1/Gemfile
source 'http://rubygems.org'
gem 'nokogiri', '1.6.1'
/dir_2/Gemfile
source 'http://rubygems.org'
gem 'nokogiri', '1.6.2'
I see two options:
You could have different Gemfiles and let bundler take care of setting the right gem-version. If the scripts are in different directories, it should be no problem.
You could use rbenv-gemset to have separate gem-environments
There are undoubtly more, but those two seem the easiest for your setup.
Multiple instances of the same ruby is possible (regardless of the tool installing them) by just compiling them manually, with a different --prefix configured.
download the source
extract it
./configure --prefix=~/.rbenv/version/2.1.2-tSquirrel
make
sudo make install
This is how the rbenv-docs propose to achieve this.
You could also rename the current "2.1.2"-directory and then use ruby-build to install 2.1.2 again.
"Versions" in rbenv are just directories in ~/.rbenv/versions, I would guess you cold just rename/copy installed version and when you "select" version with "rbenv shell" you just declare from which directory you want to use binaries.
I understand that rvm allows us to run multiple versions of ruby. Are ruby gems installed to a specific version of ruby? Say I upgraded to the latest version of ruby 2.1.1 and want to use that as my default, do I have to reinstall the ruby gems from the earlier version of ruby to this version?
If you use rvm install, you will have to install your gems anew. If you use rvm upgrade, the gems will be migrated if possible.
Check out the RVM documentation:
RVM creates a new completely separate gem directory for each version of ruby. In addition you can separate this further and have a set of gems per project/application/gerbil color... see the gemsets for more details on using sets of gems. [...]
rvm --default use <RUBYVERSION>
For example,
rvm --default use 2.1.1
You can check this. And check out RVM Documentation too.
I installed Ruby and Rails via RVM, but using "gem install something", the console tries to install into /Library/Ruby/Gems/1.8 directory.
Do I still need this Ruby dir?
You are still using the default Ruby. You need to activate RVM for your shell session. See item 2 at the below:
http://beginrescueend.com/rvm/install/
(and no I wouldn't delete the original Ruby dir)
You have to direct your shell to use RVM and the Ruby version. You can do so by issuing the following command:
rvm use *ruby version (example: 1.8.7)*
Or, if you have created a gemset for particular project:
rvm use *ruby version (example: 1.8.7)*#*my_gem_set*
I've been using the default system ruby version 1.8.7 without RVM for a few rails projects and have not run into any problems. I just recently installed RVM, and after running rvm requirements I get this output:
To use an RVM installed Ruby as default, instead of the system ruby:
rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7
I believe what these commands do are to install the same gems that have already been installed using the system ruby under the RVM installed ruby.
My questions are, am I right in what these commands do? and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The one thing that springs to mind is, if you use the system Ruby, you'll use it slightly differently that RVM's Rubies--for example, you'll likely need to use sudo to install gems. Furthermore, you won't be able to use many of RVM's features, like gemsets, with the system Ruby.
Well one reason I can think of is that you don't wanna worry about your system not working even if the system ruby gets updated.
My questions are, am I right in what these commands do?
You are right in what they do. The first command installs Ruby 1.8.7, the second command installs all the gems currently install on your system Ruby installation in the new RVM Ruby 1.8.7 installation, and the third command sets your default version of Ruby to be the RVM Ruby 1.8.7.
and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The second command is actually more of about convenience than necessity. Yes, the gems install in the RVM 1.8.7 will be completely separate from the ones installed in the system version of Ruby; however, if you didn't run the second command, you're RVM 1.8.7 would start out with almost no gems (only the defaults). That means that you would need to go through and manually install the gems that you need to get your project up and running. Instead of doing that, the second command allows you to just install the same gems you've already installed in the system version of Ruby to the RVM 1.8.7 version—it doesn't migrate them, it just makes a copy of them. After the second command, there are two distinct sets of the exact same gems: one in the system Ruby and one in the RVM 1.8.7 Ruby. So, if you were to update gems in either of the Rubies, they would get updated, but the other version's gems would be unaffected.
Hope this helps answer your question.
I am trying to setup Ruby 1.9.2-p180 on my system for project specific purposes. I already have Ruby 1.9.2-p134 and Ruby 1.8.7 with me.
Do I need to replace Ruby 1.9.2-p134 with Ruby 1.9.2-p180 or can both co exist?
I'm making use of Ubuntu 10.04 OS.
Thank you..
That's exactly what RVM is for.
rvm install 1.9.2-p180
Then to use it…
rvm use 1.9.2-p180
You can also use .rvmrc to configure projects per-directory and set the rvm default to whichever you prefer.
To list installed Ruby versions…
rvm list
:)