custom_require.rb:36:in `require': no such file to load -- myapp(LoadError) - ruby

i get the above error, all i did was install rvm and update to ruby 1.9.2 from the default ruby that you get with mac.
all my gems appear in the gem list but do i need to specify a path somewhere?
cheers,
glenno.

Check that you have the gems installed gem list If not, install as usual gem install whatever or if you want a specific version gem install whatever -v 1.2.3 Or if you have bundler in your project (ie Rails), it's just bundle install
If you have all the gems, then this is probably a local file, and you're probably coming from Ruby version < 1.9, you need to either fix your $LOAD_PATH (which will depend on too many factors for me to explain here), or specify the full path to the file you want File.dirname(__FILE__) + '/myapp'
Otherwise, you need to give more info, like what version you used to be running, what myapp is, and where it is in relation to your file.

In my case it was rvm issue, I was using rvm 1.9 when i changed it to 1.8, migration worked.
rvm use 1.8

In my case I was converting to Cygwin64. The Cygwin directory name changed and Ruby upgraded to 1.9. After I fixed the Cygwin directory name, the second solution worked. Or at least got past this problem:
require File.dirname(FILE) + '/myapp.rb'

Related

Cleaning gems from older gem version

I recently upgraded my distro (Ubuntu from 16.04 to 18.04), and I guess either on the upgrade or on the regular sudo update/upgrade calls gem was upgraded and I currently have the 2.7.6 version. I barely use Ruby lately, but just now I had to run a jekyll/bundle command which returned me that it had a bad interpreter (it was looking for ruby2.3 and it's currently installed on the 2.5 version).
My next step would be updating the jekyll and bundle gems (so they update the interpreter version), but to my surprise they aren't listed when I run gem list. They were obviously installed since there's a /usr/local/bin/jekyll executable and a /usr/local/bin/bundle one as well. But I think when gem was upgraded it started checking gems on a different folder (/var/lib/gems/2.5.0 I'm guessing) but jekyll/bundle apparently are in /var/lib/gems/2.3.0. I'd be fine just installing jekyll/bundle on the 2.5.0 version, but is there a way to remove all gem files from the older version since they are useless now?
I highly recommend you to use a ruby version manager like rvm or rbenv to manage different ruby versions installed on your system.
If you just want to remove the gems from your disk, you can find the location of each gem with the command bundle show $gem_name and delete the parent directory to delete all of them. You may need to delete the Gemfile.lock as well to reset the locked gem versions.
Here's what I recommend:
Use rbenv for multiple Ruby version management, no customizations needed
a ruby installer plugin is now included with rbenv
it also handles ruby executable shims automatically, don't need to rbenv rehash anymore
it loads really fast (rvm has a noticable load time on shell startup)
Use bundler to dynamically resolve gems at runtime (options below)
it's fast enough anyways
don't need a special gem solution, bundler comes included /w Ruby now
Options to invoke bundler dynamically (I recommend the last one):
use bundle exec in front of every ruby executable
variant: create alias be='bundle exec'
create bundle binstubs <LIST GEM EXECUTABLES YOU WANT> for each project
use bin/ in front of every ruby executable to call the binstubs
do #2 and then set up .git/safe
lets you manually allow PATH lookups to the bin/ folder while in that project root
don't need to type bin/ anymore
Now multiple gem versions will all be installed into the same Ruby version bucket, and you let bundler dynamically add the right versions to the load path before every startup.
Removing a Ruby version will also mean removing all the gems (and versions of those gems) installed for that Ruby version as well.
I'd like to thank both answers. I upvoted them because even though they're not a direct solution to my problem they give good directions to prevent it.
NOTE: These are the steps I took, which doesn't mean they are the correct way, so don't take more as a reference than a guide.
Here's what I did to clean up those old Ruby version gems:
First I needed to add an environment variable for gem to be able to find those obsolete gems, by running GEM_PATH=/var/lib/gems/2.3.0.
Then it's possible to get the contents and specification of the gems with gem contents name_of_gem and gem specification name_of_gem.
I individually uninstalled those gems that were obsolete with sudo GEM_PATH=/var/lib/gems/2.3.0 gem uninstall -i /var/lib/gems/2.3.0 name_of_gem. In my case I did a sudo install, so I needed sudo which also required me to set the environment variable again because of sudo's security policy. Also, I needed to manually set the install directory for some reason.
Some gems will have executables, and the uninstall will ask if you want to remove it. I wasn't able to get the gem uninstall to remove it because it claimed I didn't have write permission to /var/lib/gems/2.3.0/bin (which is weird because the EXECUTABLE DIRECTORY gem environment variable was /usr/local/bin). I asked gem not to remove the executables, wrote down their names and removed them manually from the EXECUTABLE DIRECTORY folder. You can also use which gem_executable_name to find out where it's located.
After uninstalling all the gems I believe it's safe to remove the /var/lib/gems/2.3.0 folder and its contents. Running gem contents on all of them only returned me files on this folder so I believe the only external files were the script/executables that were added to /usr/local/bin.

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.

Ruby, Versions, Gems, Versions and more, Oh My

Apologies for the topic title, couldn't resist.
Basically, For no reason whatsoever apart from trying out different things. I want to implode RVM and try out rbenv. Nothing against RVM, just want to try different peoples software and try different things out.
I can get rid of RVM and install rbenv no problem. Could you guys confirm a few things for me.
Firstly, if I do the above, and then install a few different ruby versions. I know I can place a .ruby-version file in a projects root directory to specify a specific ruby version but then when I say gem install <gemname> I take it that is installed globally for that ruby version.
If I then use bundler per project to manage what gems are used and I specify a gem version, what happens if the version specified in the lock file is different to the currently installed version and what happens if it's vice versa?
I just need a bit of clarification on what's doing what in regards to ruby, versions, gems and their versions.
One of the (many) lovely things about rbenv is that you can so easily look right at your ruby installation to see what's going on. For example, on my machine I can open ~/.rbenv and there's versions containing my ruby installations, such as 1.9.3-p327. Opening that, I can keep drilling down to see my gems installed for that version of ruby (in ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems). It is then trivial to run gem list or gem install somegem and confirm that what's being affected is this very collection of gems - if this is the current ruby (set in rbenv global and starred in rbenv versions).
In short, everything about your system thinks that ruby means this version of ruby and that its library is this library.
For Bundler, you'll need to install rbenv-bundler. A nice tutorial (easily found with Google) is here: http://dan.carley.co/blog/2012/02/07/rbenv-and-bundler/

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

Where is the default Gem.dir path set?

This is really odd: I installed ruby 1.9.1 using a "191" suffix so that it will coexist with other versions. e.g. the executables look like ruby191, gem191 and the library directory where all of the vendor/site code lives is /usr/local/lib/ruby191. The version of RubyGems (1.3.1) that is included with ruby 1.9.1 works fine. The installation was performed with:
cd /usr/local/src/ruby-1.9.1-p429
./configure --prefix=/usr/local --program-suffix=191
make
sudo make install
However, when I upgrade my RubyGems installation with sudo gem191 update --system it appears to forget about all of the installed gems. When I checked it out with gem191 environment it is now looking in /usr/local/lib/ruby.
I know I can create a ~/.gemrc and change the location there, but that smells like a hack to me. I have spent a couple of hours trying to figure out where Gem.dir is set in the code, but have been unable to find it. Does anyone know where the default location is set?
Apparently the Gem engine didn't work properly under ruby 1.9.1, but has been fixed under ruby 1.9.2. After installing the latest build, all of my Gem issues have disappeared.
You should definitely use rvm gem for multiple ruby installations on one system.
P.S. You can view your gem installation path by using $ gem{suffix} env.

Resources