pitachip
pitachip

Reputation: 965

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

Upvotes: 1

Views: 279

Answers (2)

Egryan
Egryan

Reputation: 717

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

Upvotes: 1

quandrum
quandrum

Reputation: 1646

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.

Upvotes: 0

Related Questions