Can't find my ruby gems - ruby

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

Related

How do I know if I have a gem on my local machine?

I have the Rails gem and the data_mapper gem installed on my local machine (macbook). When I am in my terminal, I can type which rails and it give me a directory like /Users/andyhuynh/.rvm/gems/ruby-1.9.3-p392/bin/rails.
However, if I type which data_mapper, I get data_mapper not found. How am I able to figure out what gems I have installed on my local machine? Many thanks for any help!
How do I know if I have a gem on my local machine?
Type gem list.
You are searching for executable files with which. You can list all gems with gems list or bundle list if you are using bundler.
You can search for specific gem with gem list | grep gemname or bundle show gemname.
In case you are using RVM or any other Ruby version manager, you might have it install in other Ruby version.
rvm list
will let you know which version you have installed and which one you are using. Check on other versions with:
rvm use 'ruby_version'
and then
gem list gemname

'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.

Bundler and gems on github

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 #

Where should i put my rubygems after installation?

Suppose I installed some ruby gems using gem install gemname. Where should I install them, and when what directory should I run gem install rubygems-update-1.3.1.gem from?
gem env
will tell you where they were installed.
In general on windows it doesn't matter what directory you're in, running
gem update --system
will work from anywhere.
-r
They are automatically installed to your GEM_HOME. In Linux, you can open a terminal and type:
echo $GEM_HOME
To find out where that is exactly.
Is the place where you view your all gems list for linux.
/usr/lib/ruby/gems
You shouldn't need to be in any specific directory; running gem install will put the gem in the directory that gem expects your gems to be.
As mentioned in other answers, if you want to see where that directory is, run gem env and take a look at the INSTALLATION DIRECTORY: line.

Resources