Bundler and gems on github - ruby

So when you have bundler install a gem from github, it doesn't actually get installed, does it? gem list won't list those gems.
Which brings me to my conundrum: I'm working on a script that wants to use one of these gems that don't actually get installed. Now what? I could check out the github repo manually and build/install the gem, but now I've got one version being managed by bundler and another that's not. I could point the script to the gem directory in ~/.rvm but that's not a great idea when it comes time to go to production.
I'm trying to find a bundler command that will make any gems from github "register" with rubygems, but nothing so far. Any suggestions?

Ironically this is the same answer as a previous question I had, which I answered myself with this same solution (although it was a little different in bundler 0.9):
require 'rubygems'
require 'bundler/setup'
require 'hiddengem'
bundler/setup makes the bundler "stack" available just as if they were regularly installed gems. Sooner or later I'll remember this. :)

rubygems-bundler is a gem that addresses this issue. If it is installed on your system, you shouldn't need any extra code in your project. It may need to be installed as #global, so, to sum it all up:
$ rvm use #global
$ gem install rubygems-bundler
And then, to get back to the rvm version you were using:
$ rvm use #

Related

Why can't bundler find rake when it's obviously installed?

I'm trying to migrate a version of Redmine from backup to a new server; I'm migrating from Redmine 3.2.3 to 3.3.0. I installed the new version of Redmine (from Bitnami Stack) on my new server and everything loads properly. When I move my old database into the new version, I have to run
bundle exec rake db:migrate
to migrate my database. But... bundler can't find rake somehow even though gem list shows it clearly installed. Can I force bundler to use the version of rake that I have installed that it says I don't?
I should mention I've done no customization at all, haven't installed any gems, or changed ruby versions or done anything. This is out of the box Redmine.
I noticed after I made the question that I had two versions of rake installed. I removed both and reinstalled rake 11.1.2 and have the same problem.
You are probably using the wrong ruby binary. Note that, the installers for Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system.
Also, taking a look at the screenshots you have shared, you were using ruby 1.9.3 when you have executed ruby -v and the Redmine Bitnami Stacks uses ruby 2.1.9. Probably this is the reason of the issue you are having.
If you want to use the ruby (and the other components) shipped with the Bitnami Stack you need to run the following command:
cd *INSTALLDIR*
./use_redmine
This command will open a new console session with the environment configured to use the stack.
There are two things:
ruby gems available via gem list
ruby gems availbale via bundler
When you are using bundle then bundler is looking for gem from Gemfile. You can have multiple gems installed in your system, but when you are using Gemfile then gem version will be taken from Gemfile.lock
Summing up:
$ bundle exec rake ...
require to have rake gem inside Gemfile
$ rake ...
it will take the newest version of rake gem installed in system
I hope it helps you.
This is how I finally got my Redmine upgraded:
A version of ruby outside of the one provided by Bitnami somehow got installed on this machine as well as another version of bundler. The first thing I did was uninstall the apt-get version of bundler. I had to manually remove /usr/bin/bundler and /usr/bin/bundle for $ which bundle to stop finding bundler even after the removal.
I saw that the Bitnami stack's ruby was version 2.1.x but found Ruby 1.9.3 was installed to /usr/bin/ruby1.9.3/ with $ which ruby. I took the commands from here and removed that version of Ruby.
Running $ ruby -v now gave me nothing as Ruby wasn't installed anymore (even though it was in the Bitnami stack). Bitnami's Ruby then had to be (re?)added to my path in ~/.profile. $ ruby -v now gives me the correct version.
$ gem list was no longer telling me that rake was installed. I tried running $ bundle install where Gemfile is but was complaining about mime-types being locked at a lower version and wouldn't do anything. I got around that with $ bundle update but then ran into the infamous nokogiri problem where it complains that everything required by nokogiri isn't installed.
Since I'd dealt with this before (many many times) I went over to the Nokogiri Website's install page and followed the instructions for troubleshooting on Ubuntu:
sudo apt-get install build-essential patch
sudo apt-get install ruby-dev zlib1g-dev liblzma-dev
and now $ bundle update worked on my Gemfile. Redmine upgraded and my users are about as happy as users can get.

Can't find my ruby gems

I have been using gems fine. I use compass watch to map changes to my scss files to css files.
I hadn't used it for a week. I tried doing compass watch, and now its telling me compass isn't installed. I did a gem list command and I only have six gems locally now. I looked in my ruby gems folder in my install and All my gems are there.
Any idea what could be going on? Do I uninstall ruby and do it all over again?
You can get all the details about your Ruby environment by typing:
gem env
In the output look for - GEM PATHS: to know exactly where your gems are stored. You can have more than one gemset.
Are you using any kind of a version manager, like RVM, because if so, your gems might be in a different gemset.
You could run the following command to check the gemset:
rvm gemset list

"bundle install" for Ruby 1.8.7 on Ubuntu Raring Ringtail 13.04

I'm not a rubyist and there might be something obvious I'm missing.
I've wrote an application in Ruby 1.8.7, I'm trying to package it in Vagrant (running Raring 13.04), but I've to run "bundle install" to install the requirements and even though gem1.8 does exist, running bundle install still install the gems for Ruby 1.9.3. And then my program fails at runtime...
Any idea about how to solve this?
UPDATE 1
The related Gemfile (thanks to the first answerers):
ruby '1.8.7'
# ...
gem 'trollop'
but for ruby1.8 myfile.rb an error is raised
no such file to load -- trollop (LoadError)
After investigation, the problem looks in bundle install:
Your Ruby version is 1.9.3, but your Gemfile specified 1.8.7
I don't get how to solve the problem.
UPDATE 2
After following the advices from #klaffenboeck things have changed. I'm using RVM and have Ruby 1.8.7 when entering in the project folder. Bundler seems to install things correctly, however the require seems to fail... Path problem?
See here for detail about Vagrant / RVM setup: https://rvm.io/integration/vagrant
UPDATE 3
Problem solved, I was missing a:
require 'rubygems'
before all gems (it worked locally but not in Vagrant).
Bundler will install gems (by default) for whichever Ruby is in your PATH.
Try /usr/bin/env ruby -v or which ruby to figure out which one that is; my guess is you're running bundler with Ruby 1.8.
Adding
ruby '1.8.7'
on top of your Gemfile will help diagnose.
Not aware of this problem in general, but try to put the ruby-version at the top of your gemfile:
#Gemfile
ruby '1.8.7'
# followed by your gems
Edit:
this is most likely because your Gemfile.lock states ruby 1.9.3 - run bundle update
Try running gem uninstall bundler, then gem1.8 install bundler.
Your bundle command seems to be running under Ruby 1.9.3. You can verify which ruby executable bundler is using with head -n 1 $(which bundle). You want it to be ruby1.8.

'require' not working with rvm

The following code lives inside my rails app's root folder and daemonizes/runs myserver.rb.
# myserver_control.rb
require 'rubygems'
require 'daemons' # causes 'no such file to load -- daemons' error since gem reinstall with rvm
#options = {
# options defined
}
Daemons.run('myserver.rb', #options)
It was working just fine until I installed rvm and now it can't seem to find the daemons gem. I have a feeling maybe the above is searching for the daemons gem in a system wide folder somewhere? Instead of being able to use the rvm installed daemons gem? How do I install the daemons gem on a system level where it can find it? OR how do I make it so it can find the rvm installed gem?
Currently I do not even have a 'system' gem set. How would I install gems on the system level after having already installed rvm?
If wishing to use the system ruby and gems you can type in
rvm use system
which will allow to use the system installed ruby and gems, but I think this kinda of defeats the purpose of using RVM I would instead install a default ruby in RVM and install any gems into that. To set a default Ruby after you have installed it, type this
rvm --default use 1.9.2
Edit
Based on comment your problem lies with running sudo, this creates a new subshell and different instance of rvm
RVM uses a concept of gemsets, which are unique groups of gems that you can use, most often specific to ruby versions (although you can make them specific to applications or global).
RVM will change your GEM_HOME when changing ruby versions, which tells ru ygems where your gems are installed. So when you installed RVM, you created a new blank gemset and RVM told rubygems to use that.
This is because gems are not always cross compatible between rubygems.
However, if you just writing rails apps, you should ignore the above for now and use bundler. Place 'gem "daemon"' I am your Gemfile and run bundle update from your app root directory.
Bundle helps you maintain gems on a per app basis, which means your app won't break if you upgrade a gem somewhere else. Using it and knowing how it works is best practices. Good luck.

gem server using rvm

Hopefully an easy one - started using rvm and one of the benefits it gives aside from easily switching between gemsets and ruby versions is that I no longer need to install new gems under root (So, no need for sudo). Back when I used to do that, the way i got to my gem docs was by running;
gem server
which gave me a home-hosted site so i could browse the documentation. Now, when I install a gem I don't need to do it under root,
#so it's just
gem install hpricot
but when I then run gem server, it only lists those gems I've installed under root. So what I'm finding myself doing is;
gem install hpricot #to get the gem under rvm
sudo gem install hrpicot #so i can still use gem server
Am I missing something or is this just how it is? I work a lot offline so really need those local docs.
Running gem server under a particular ruby/gemset works well for me. Check rvm info to make sure your shell vars are pointing to the correct ruby/gemset. Also, which version of rvm are you running? I've ran rvm get head a few weeks ago and the version it's showing for me is rvm 1.9.2.

Resources