Ruby Gem Listed, But Won't Load (Gem in User Dir, Not Ruby Dir)

Ruby gem listed, but won't load (gem in user dir, not ruby dir)

I had the same problem, I fixed it by adding the following at the top of the ruby file

require 'rubygems'

Hope that helps

Ruby gem listed, but won't load (gem in user dir, not ruby dir)

I had the same problem, I fixed it by adding the following at the top of the ruby file

require 'rubygems'

Hope that helps

Ruby gems not being loaded

Thanks very much to Josh and grenierm5 for their time and advice - RBENV was a great help, definitely makes life easier.

The answer is two-part: RBENV to solve my weird environment issues, but then also to solve the mysql gem install issue, I had to install the following Debian packages:

apt-get install mysql-client libmysqlclient-dev

This was answered here: ERROR: Failed to build gem native extension (mysql2 on rails 3.2.3)

Making a Ruby Gem - Cannot Load Such File

The spec.files entry of your gemspec doesn’t include the mygem.rb file, so that file won‘t be in the gem when it is built. Only files listed in this entry will be included in the final gem.

The simplest solution would be to just add mygem.rb to the array:

spec.files = ['lib/command.rb', 'lib/connection.rb', 'lib/mygem.rb']

This is a fairly simple fix, you might want to do something more flexible like using a Dir glob:

spec.files = Dir['lib/**/*.rb']

In fact the Rubygems guide suggests you do something like this (text is from the end of that section):

If you’ve added more files to your gem, make sure to remember to add them to your gemspec’s files array before publishing a new gem! For this reason (among others), many developers automate this with Hoe, Jeweler, Rake, Bundler, or just a dynamic gemspec.


Also, you really do need to fix your permissions problem, you shouldn’t need sudo to install gems into your own home directory.

gem server won't serve gems

I solved this pretty easily.

I don't even use a dedicated gem server.

I did the following:

  1. Create a directory on your apache web server that is servable and create a gems subdir in it. For example:
    mkdir -p /var/www/rubygems/gems

  2. Put all gems you want to serve to the created gems subdirectory: cp /my/gems/dir/*.gem /var/www/rubygems/gems

  3. Generate the gem index:
    gem generate_index -d /var/www/rubygems

  4. Do not forget to adapt the access rights so that your web server can read the contents

INFO: The index has to be generated in the directory that contains the gems subdir, not the gems dir itself! In this case it's /var/www/rubygems.

Now you can add http://<my-gem-server>.domain/rubygems to your gem sources

JRuby won't install gems in correct path

After trying out for days, I used the bundle config documentation which says to use bundle config list to view the set configs.

Through this, I found that the bundler had set a path for where the gems should be installed.

After deleting the config, everything seems to work normally as it should!

Ruby gems won't load even though installed

Your gem env and Gem.path are inconsistent.


Your Gem.path is looking at ["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"] but your gem env is looking at /opt/ruby1.9/lib/ruby/gems/1.9.1

As a quick check, why not create a symlink from /opt/ruby1.9/lib/ruby/gems/1.9.1
to /opt/ruby1.9/lib/ruby1.9/gems/1.9.1 to /opt/ruby1.9/lib/ruby/gems/1.9.1

sudo ln -s /opt/ruby1.9/lib/ruby1.9/gems/1.9.1  /opt/ruby1.9/lib/ruby/gems/1.9.1

Configure gem installation directory to match user installation directory

I ended up putting this atrocity in my init scripts:

if [ ! -z "`which gem`" ]; then
GEM_HOME=`prefix=" - USER INSTALLATION DIRECTORY: "; line=\`gem env | grep "^$prefix"\`; suffix=${line#$prefix}; echo $suffix`
fi;


Related Topics



Leave a reply



Submit