Different search paths when installing Ruby via RVM - ruby

I am using Puppet together with Librarian Puppet. Puppet is installed via the system's package manager, Librarian Puppet via Ruby gem. It only works when I install Ruby (1.9.3) via Debian's package manager. When I use RVM with the identical or another version (>= 1.9.3), I get an error from Librarian, saying that it cannot find puppet. Line 4 require 'puppet' in local.rbcauses the problem in Librarian. The puppet gem-based installation is not recommended and I don't want to do it that way. After some hours debugging, I found out that Ruby's search path differs when you use the package manager or RVM. Using RVM with Ruby 2.1.2, I get:
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/x86_64-linux
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/vendor_ruby/2.1.0
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/vendor_ruby/2.1.0/x86_64-linux
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/vendor_ruby
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/x86_64-linux
The puppet.rbis located at /usr/lib/ruby/vendor_ruby. This path is part of the search path if I install Ruby via Debian's package manager!
/usr/local/lib/site_ruby
...
/usr/lib/ruby/vendor_ruby
Is there any solution without installing puppet via gem?

librarian-puppet needs the puppet gem to parse the dependencies' Modulefile when using git and path modules. Not for Forge modules though
https://github.com/rodjek/librarian-puppet/blob/master/lib/librarian/puppet/source/local.rb#L8
https://github.com/rodjek/librarian-puppet/pull/62

Related

Local gem repository? Install a ruby gem without 'gem'?

Is it possibile to have something like a 'local' gem repository for Ruby?
I'm working on a custom Linux distribution without admin rights. Ruby is installed on the machine (v.1.8.7) but apparently no 'gem' or 'bundle' or whatever are installed. I need to use some Ruby gems like Nokogiri.
Is it possible to use Ruby gems without installing them through gem install?
Yes. Any gem can be used standalone. You just have to either download the source from github, or download the gem and extract its contents manually.
After you've done that you have to add the lib folder of the gem into the load path ($:) of Ruby. For example:
$:.unshift(File.expand_path("nokogiri-1.6.1/lib"))
require 'nokogiri'
Assuming you are running Ruby in the current directory and the Nokogiri source is in the folder nokogiri-1.6.1.
But remember that first you have to do the same with all Nokogiri prerequisites. I.e. all the libraries Nokogiri depends on.
Another option, which is what I would do, is to install RubyGems in your home directory. That can get a little bit tricky though, but it's possible by downloading the RubyGems package and running something like:
ruby setup.rb --prefix=/home/my_user_name/rubygems
Then you need to set up the ENV variables GEM_HOME and GEM_PATH to point to a location in your home directory where you want all your gems to be installed. See "What's the difference between GEM_HOME and GEM_PATH?" for a description of what they do.
You will also need to add something like /home/my_user_name/rubygems/bin to your PATH so that the gem command can be found by the shell.

Is it possible to install and use a Ruby distribution alongside a PC with Opscode Chef Client without one affecting the other?

I'm running chef-client on Windows, and as it happens, the Ruby distribution (1.9.3) embedded in Chef-Client is available system-wide. I believe this is necessary in order to have chef-client function properly? I have tried installing another Ruby distribution (namely, v2.0) but that seems to break Chef-Client.
What I was hoping to achieve is to have chef-client install & configure a Ruby app written against v2.0, so that I can run that app with v2 but have chef-client continue to use the embedded Ruby distribution.
Would that not be possible?
Sure, that's why Opscode is using their Omnibus packages, which ships everything required to run Chef.
Use the "gem_binary" attribute to specify the ruby distro:
gem_package "somegem" do
gem_binary "/usr/bin/gem"
action :install
end
The documentation describe the parameter as follows:
gem_binary: An attribute for the gem_package provider that is used to specify a gems binary. This attribute is useful when installing Ruby 1.9 gems while running in Ruby 1.8. By default, the same version of Ruby that is used by the chef-client will be installed.

How to use Bundler with path specified Ruby version

I am on a VM (Lucid 64b) with a system Ruby version of 1.9.3p0.
I have a Ruby script that creates a .deb file -- The script needs to use Ruby 1.8.7 which I have installed in /foo/ruby/1.8.7.
There is an existing Gemfile to be used with Bundler
I can't use RVM and I can't install gems at the system level.
My .bashrc includes (and has been sourced)
export PATH=$PATH:/foo/ruby/1.8.7/bin
but ruby -v still gives me
ruby 1.9.3p0 (2011-10-30) [x86_64-linux]
Questions
How can I change the Ruby version for my user to use Ruby 1.8.7?
I've run: bundle install --path vendor/bundle
So in that directory (actually ./vendor/bundle/ruby/1.8/cache/gems) are all the gems I need but, when I run the Ruby script it doesn't find the required gems. I run the script like so /foo/ruby/1.8.7 script_to_gen_deb_file.rb
How can I get ruby to see/use the bundled gems?
Update
I was able to solve it. I needed to use
/foo/ruby1.8.7/bundle exec /foo/ruby1.8.7/ruby script_to_gen_deb_file.rb
I had tried this before, but I got an unrelated error and believed there was an environment problem.
Change your path so the special ruby gets precedence?
export PATH=/foo/ruby/1.8.7/bin:$PATH

ruby gem install issue - ERROR: Could not find a valid gem 'vim-ruby' (>= 0) in any repository

I typed following command in prompt:
# gem install vim-ruby --remote
then got a error message:
ERROR: Could not find a valid gem 'vim-ruby' (>= 0) in any repository
My environment is windows xp and ruby's version is 1.9.3
how to solve it?
vim-ruby is not a gem. Checking the gem repository using gem list vim -r returns several gems, but not that one.
From the docs:
How you get these files into Vim:
[...]
By downloading one of the tarballs, you can easily install the latest
stable or development version wherever you like on your machine. No
README, no vim-ruby-install.rb, just Vim files. You would typically
install these into either $VIM/vimfiles, for system-wide use, or $HOME/.vim
($HOME/vimfiles on Windows) for personal use.
Remember that when you install Vim in the first place, all of these files
are present. The purpose of downloading and installing them from
github is to get the latest version of them.
vim-ruby is not a gem but the page: https://github.com/vim-ruby/vim-ruby has a link https://github.com/vim-ruby/vim-ruby/wiki in which the link "VimRubySupport" has a section "Installing the latest version" which shows the vim-ruby as a gem. I too had the same problem as the original post. I downloaded the archive file from http://rubyforge.org/projects/vim-ruby/ which has a .rb file (bin/vim-ruby-install.rb after untarring the archive in my case) which installs the required vim files.
This method should solve your issue:
$ gem install --http-proxy http://201.187.107.19:8080 vim-ruby
Note, the IP address and the port number refers to a proxy. You should search for a proxy list and use one of the proxies there.
This is sample site with proxies: http://www.cybersyndrome.net/pla5.html

Ruby: How to include/install .bundle?

I'm new to Ruby. I have a .bundle file. I put it in the source folder and did
require('my.bundle')
But when I call the methods in the bundle, the definition is not found. Do I have to install them or include them in some other way to access them?
I am on Ruby version 1.8.7 (latest version on Mac).
I highly recommend using RVM to manage your Ruby installation, including your gems, so if you don't already have that, get it and follow the instructions for installing it. Make sure you do the part about modifying your bash startup script or you'll see weird behavior, like the wrong Ruby being called. Also, use the steps in "RVM and RubyGems" to install your gems or you can run into weird behavior with gems being installed under the wrong or an unexpected Ruby.
Second, use the gem command to install gems:
gem install gem_to_install
replacing "gem_to_install" with the name of the gem you want, and it will be installed into the appropriate gem folder for your Ruby.
If you are on Ruby 1.92, and trying to require a gem to use as a module in your code, use:
require 'gemname'
if it is installed via the gem command. And, if it is a module you wrote or have in your program's directory or below it, use:
require_relative 'path/to/gem/gemname'
If you are on a Ruby < 1.9 you'll also need to add require 'rubygems' above your other require lines, then use require './path/to/gem/gemname'.
Thanks, but my .bundle is not in gems. How do I install/require a .bundle file I already have?
If you wrote it look into rubygems/gemcutter or bundler for info on bundling and managing gems.
You can install a gem without using the app by going into the directory containing the gem and running setup.rb. See http://i.loveruby.net/en/projects/setup/doc/usage.html for a decent writeup or the official docs at: http://docs.rubygems.org/read/chapter/3

Resources