I want to configure gem to only use system gems - never those in $HOME/.gem. This is because I'm writing a script that will access Gem.path and I don't want it to return the path to gems in my home directory.
I'm pretty sure I haven't explicitly set GEM_HOME or anything like that in my .bashrc, .bash_login etc.
But Gem.path returns my homedir gems first:
irb
> Gem.path
=> ["/home/nfm/.gem/ruby/1.9.1", "/usr/local/lib/ruby/gems/1.9.1"]
Can I stop this from happening? Where is it configured? Or is it just the default to look in homedir first?
If I can't configure this, can I return the system path for gems with regexp hackery?
More details:
which ruby
/usr/local/bin/ruby
ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
gem env
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.9.1
- /home/nfm/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Update:
So apparently this can be configured in ~/.gemrc:
# Note the use of a symbol before the colon - the string version doesn't work!
:gempath:
- /usr/local/lib/ruby/gems/1.9.1
However, this does not seem to take effect if you fire up irb. This has something to do with the fact that the config file is YAML, and apparently yaml isn't loaded when irb starts (not sure on this one!):
$ irb
> Gem.path
=> ["/home/nfm/.gem/ruby/1.9.1", "/usr/local/lib/ruby/gems/1.9.1"]
> Gem.configuration.path
=> ["/usr/local/lib/ruby/gems/1.9.1"]
# Ready for a WTF moment?
> Gem.path
=> ["/usr/local/lib/ruby/gems/1.9.1"]
So, the answer below seems like the only consistent way to get the correct behavior, even though you'd assume that ~/.gemrc would work and would be a nicer way to wrap you config up.
However, setting :gempath: in my ~/.gemrc worked in the context of the script being in my Rakefile in a Rails app, presumably because yaml is explicitly loaded.
Not sure exactly what's going on with yaml, but this explanation seems consistent with what I'm seeing here.
Mod up! :P
overwrite it here:
#in ~/.bashrc
export GEM_PATH=/usr/local/lib/ruby/gems/1.9.1
Related
I am using:
TextMate: version 2.0-alpha.9511
rvm: 1.25.15 (stable)
ruby: version 2.1.0p0
oh-my-zshell: 5.0.2
Mac OS X: 10.9.1 (Mavericks)
I have rvm and textmate set up to use
TM_RUBY=/Users/<myuser>/.rvm/bin/rvm-auto-ruby
The problem:
when I try to run my rake tasks using the rake bundle in textmate, I get some errors about the file not loading: "cannot load such file -- rubocop/rake_task"
The clue:
I changed my rakefile so that it simply reports the "gem env" for the default task.
When I then run the task, I see a completely different gem environment, than I would see if I used rake at the terminal command line.
RakeMate v2.0.0
>>> /Users/Johno/Projects/puzzles/triangle/Rakefile
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [universal.x86_64-darwin13]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-13
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/Johno/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
Whereas I see this when running
$ gem env
in my terminal, for my project
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.0.rc.1
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin12.0]
- INSTALLATION DIRECTORY: /Users/Johno/.rvm/gems/ruby-2.1.0#puzzles
- RUBY EXECUTABLE: /Users/Johno/.rvm/rubies/ruby-2.1.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/Johno/.rvm/gems/ruby-2.1.0#puzzles/bin
- SPEC CACHE DIRECTORY: /Users/Johno/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-12
- GEM PATHS:
- /Users/Johno/.rvm/gems/ruby-2.1.0#puzzles
- /Users/Johno/.rvm/gems/ruby-2.1.0#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/Johno/.rvm/gems/ruby-2.1.0#puzzles/bin
- /Users/Johno/.rvm/gems/ruby-2.1.0#global/bin
- /Users/Johno/.rvm/rubies/ruby-2.1.0/bin
- /Users/Johno/.rvm/bin
- /usr/local/bin
- /Users/Johno/Projects/Scripts/Ruby
- /Users/Johno/Projects/Scripts/bash
- /Users/Johno/Projects/Scripts/perl
- /Users/Johno/Projects/Scripts/Geek Tool
- /usr/bin
- /bin
I suspect that textmate is trying to use the "wrong" rake, or failing to set up the environment properly.
I think the problem may lie in the ruby bundle command from text mate:
#!/usr/bin/env bash
export RUBYLIB="$TM_BUNDLE_SUPPORT/RakeMate${RUBYLIB:+:$RUBYLIB}"
export TM_RAKE=$(which "${TM_RAKE:-rake}")
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby" -- "$TM_BUNDLE_SUPPORT/RakeMate/rake_mate.rb"
It appears to be using a specific ruby (1.8) rather than the rvm project specific ruby
Does anyone have a suggestion as to how to resolve this?
Thank you,
John Schank
Followed the advice to set TM_RAKE and it didn't help.
I tried both the suggested setting, and using the results of which rake
/Users/Johno/.rvm/gems/ruby-2.1.0#puzzles/bin/rake
When using my TM_RAKE, is get a different error
RakeMate v2.0.0
>>> /Users/Johno/Projects/puzzles/triangle/Rakefile
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'rake' (>= 0) among 5 total gem(s) (Gem::LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
from /Users/Johno/.rvm/gems/ruby-2.1.0#puzzles/bin/rake:22:in `<main>'
This happens to be the same error I get when I try to use the rubocop.tmbundle
It still looks to me like the gem environment is not being passed to the child process.
I solved my own problem.
Here are the details for anyone else who has this problem...
First, the answer in this question TextMate, rvm and TM_RUBY
is almost perfect.
I had to create a textmate_ruby, and a textmate_rake script, and reference them in the variables in text mate: TM_RUBY, and TM_RAKE.
Second, since I'm using zsh, I had to change the shebang line in the textmate_xxx scripts to use zsh.
Finally, the key that helped me arrive at the correct solution is that I modified my project rakefile to :
task :default do
system "gem env"
system "ruby --version"
system "pwd"
system "printenv"
end
Then when I ran the rake task in textmate, it would dump the current values of my environment, ruby version, current directory, and gem environment. This really helped to see what was going on.
It seems that TextMate is still using your system rake instead of rvm's.
Try to set TM_RAKE in addition to TM_RUBY:
TM_RAKE=$HOME/.rvm/bin/rake
This also applies to rbenv, where you would set TM_RAKE to $HOME/.rbenv/shims/rake.
I'm new to ruby and I have a problem loading gems.
I've read every topic about this on SO but I couldn't figure out how to make it work :/
I'm on a fresh install of Ruby 1.9.3 and RubyGems 1.8.11
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [i386-mingw32]
- INSTALLATION DIRECTORY: D:/dev/Ruby/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: D:/dev/Ruby/bin/ruby.exe
- EXECUTABLE DIRECTORY: D:/dev/Ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- D:/dev/Ruby/lib/ruby/gems/1.9.1
- D:/aoi/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I've installed the gem twice, once from command line
gem install soap4r
And second time i've tried to use RubyMine installer, but the result where the same,
when I try to
require 'rubygems'
resuire 'soap'
The output is the same :
LoadError: cannot load such file -- soap
from D:/dev/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from D:/dev/Ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):1
from D:/dev/Ruby/bin/irb:12:in `<main>'
Thank you for your help.
Get this https://github.com/spox/soap4r-spox and patch your ruby with it, its the default soap module for ruby but was pulled out of 1.9 versions
Try to add this to the top of your file:
gem 'soap4r'
require 'soap/wsdlDriver'
Or as an alternative try Savon
Have you checked that you do not run multiple different ruby versions ? Then your gems are not bound to the correct ruby version.
Moreover, I notice something strange :
http://rubygems.org/gems/soap : "This gem has been yanked, but it is still available for download for other gems that may have depended on it"
On the contrary, there seems to be another more interesting gem around : soap4r.
There is a tuto here. I especially noticed that sort of lines :
require "soap/rpc/standaloneserver"
That means "require soap" may not be sufficient in your case.
I'm attempting to write a crawler using the anemone gem, which requires the robots gem. For whatever reason, robots absolutely will not include. Here is some of my environment info:
$ gem list -d robots
*** LOCAL GEMS ***
robots (0.10.1)
Author: Kyle Maxwell
Homepage: http://github.com/fizx/robots
Installed at: /usr/local/lib/ruby/gems/1.9.1
Simple robots.txt parser
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-darwin10.7.0]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.9.1
- /Users/ryan/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
$ gem which robots
/usr/local/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib/robots.rb
Any ideas? All other gems load correctly, I've never had this problem before. Note that I am using ruby version 1.9, so rubygems is implicitly required. Adding
require 'rubygems'
...to the front of a script returns false, since the file is already included, and does not help the situation. Any ideas?
EDIT: Posting examples of failing code. Please note that rubygems returning false does not mean rubygems cannot load - rather that it has already been loaded. See this post: http://www.ruby-forum.com/topic/157442
$ irb
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'active_record'
=> true
irb(main):003:0> require 'mechanize'
=> true
irb(main):004:0> require 'robots'
LoadError: no such file to load -- robots
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from (irb):4
from /usr/local/bin/irb:12:in `<main>'
irb(main):005:0>
It looks like the gem has been created with the wrong permissions; there's a bug opened for this on github.
Changing the permissions with
sudo chmod a+r /usr/local/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib/robots.rb
should fix it, but watch out for other permission issues. You might be better with
sudo chmod -R a+r /usr/local/lib/ruby/gems/1.9.1/gems/robots-0.10.1
to recursively make all the files in the gem readable.
The robots.rb file (and some others) is being installed with the permissions -rw-rw----, so anyone using a local install of rvm or similar where gems are installed as the local user won't have been affected by this.
I have some gems installed, and I'm trying to use them in a Ruby app:
require 'rubygems'
require 'mygem'
When I run the app, though, I get this error: <internal:lib/rubygems/custom_require>:29:inrequire': no such file to load -- mygem (LoadError)`
But if I try requiring the gem inside irb (making sure to `require 'rubygems' first), it works fine. What am I supposed to do? I tried googling for this problem, but didn't understand.
Running a which on ruby, gem, and irb shows that they're all in /opt/local/bin/, i.e.,
> which ruby
/opt/local/bin/ruby
> which gem
/opt/local/bin/gem
> which irb
/opt/local/bin/irb
Update to answer the questions posed (yep, irb and ruby are pointing to different folders):
$LOAD_PATH and $: in irb both contain seem to be pointing to ruby 1.8 folders:
/opt/local/lib/ruby/site_ruby/1.8
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/site_ruby
/opt/local/lib/ruby/vendor_ruby/1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/vendor_ruby
/opt/local/lib/ruby/1.8
/opt/local/lib/ruby/1.8/i686-darwin10
.
$: in ruby points to ruby 1.9.1 folders:
/usr/local/lib/ruby/site_ruby/1.9.1
/usr/local/lib/ruby/site_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/1.9.1
/usr/local/lib/ruby/1.9.1/i386-darwin9.8.0
gem env shows
RubyGems Environment:
- RUBYGEMS VERSION: 1.4.1
- RUBY VERSION: 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gempath" => ["/opt/local/lib/ruby/gems/1.8"]
- :sources => ["http://rubygems.org/", "http://gems.github.com", "http://gems.github.com"]
- REMOTE SOURCES:
- http://rubygems.org/
- http://gems.github.com
- http://gems.github.com
Gem.path in irb points to
/Users/grautur/.gem/ruby/1.8
/usr/local/lib/ruby/gems/1.8
Gem.path in ruby points to
/Users/grautur/.gem/ruby/1.9.1
/usr/local/lib/ruby/gems/1.9.1
I'm not sure what's going on. However, the following may help.
In irb, do
require 'rubygems'
require 'mygem'
puts $:
and then, in ruby, do
require 'rubygems'
puts $:
and show us what you get if you haven't worked it out.
Edit: also print out the results of doing gem env on the command line.
Edit 2: See what happens if you type in puts Gem.path after you've required rubygems in both irb and ruby. See thanks to Matt for describing Rubygems
You may try to add gem 'mygem' before the require, but that should not be necessary.
You will have to add gem install mygem in your Gamefile and then run bundle install command. Your application will work correctly after doing this.
I had a similar problem. The solution I found eventually was to setup rvm (ruby version manager) on my system and use it to setup a new ruby environment. it also makes it easy to switch between ruby versions of sets of gems.
I recently upgraded to Ubuntu 9.04 and I have issues using gems.
I installed Ruby, Rubygems and Rails using apt-get.
The rails command does work.
I then installed capistrano and other gems, such as heroku.
In order to do that, I used the command:
sudo gem install XXX
When I want to use the cap command it does not work:
bash: cap: command not found
It is the same with the other gem commands.
Do I have something particular to do so that the gem commands work?
Where are my Gems?
You can find where your gems are stored using the gem environment command. For example:
chris#chris-laptop:~$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.2
- RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/chris/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
If you look at the "GEM PATHS:" section you can see that gems can be stored in two places on my laptop: /usr/lib/ruby/gems/1.8 or in the .gem directory in my home dir.
You can also see that executables are stored in EXECUTABLE DIRECTORY which in this case is /usr/bin.
Because /usr/bin is in my path this lets me run cap, merb, rails etc.
Updating your PATH
If for some reason your EXECUTABLE DIRECTORY isn't on your path (for example if it is /var/lib/gems/1.8/bin) then you need to update your PATH variable.
Assuming that you are using the bash shell. You can do this quickly for the current session by typing the following at the shell prompt; let's pretend that you want to add /var/lib/gems/1.8/bin to the path:
export PATH=$PATH:/var/lib/gems/1.8/bin
and press return. That appends the new directory to the end of the current path. Note the colon between $PATH and /var/lib/gems/1.8/bin
To set the value for all sessions you will need to edit either your .profile or .bashrc file and add the same line to the end of the file. I usually edit my .bashrc file for no reason other than that's what I've always done. When finished, save the file and then refresh your environment by typing:
bash
at the shell prompt. That will cause the .bashrc to get reread.
At any point you can check the current value of $PATH by typing
echo $PATH
at the shell prompt.
Here's a sample from one of my own servers, where my username is "chris" and the machine name is "chris-laptop":
chris#chris-laptop:~$
chris#chris-laptop:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
chris#chris-laptop:~$
chris#chris-laptop:~$ export PATH=$PATH:/var/lib/gems/1.8/bin
chris#chris-laptop:~$
chris#chris-laptop:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin
chris#chris-laptop:~$
My Gem won't load!
"Ruby gems won't load even though installed" highlights a common problem using multiple different versions of Ruby; Sometimes the Gem environment and Gem path get out of sync:
rb(main):003:0> Gem.path
=> ["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"]
irb(main):004:0> exit
Any Ruby process here is looking only in one place for its Gems.
:~/$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.1 (2009-05-12 patchlevel 129) [x86_64-linux]
- INSTALLATION DIRECTORY: /opt/ruby1.9/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /opt/ruby1.9/bin/ruby1.9
- EXECUTABLE DIRECTORY: /opt/ruby1.9/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /opt/ruby1.9/lib/ruby/gems/1.9.1
- /home/mark/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Look carefully at the output of gem environment:
- GEM PATHS:
- /opt/ruby1.9/lib/ruby/gems/1.9.1
This isn't the same path as returned by Gem.path:
["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"]
It's hard to say what exactly caused lib/ruby to change to lib/ruby1.9 but most likely the developer was working with multiple Ruby versions. A quick mv or ln will solve the problem.
If you do need to work with multiple Ruby versions then you really should be using rvm.
As noted by #Chris you need to add the gems environment to your path. You can do this by:
echo 'export PATH=$PATH:/var/lib/gems/1.8/bin' | tee --append ~/.bashrc
The folder in which gems are stored must be on your PATH, for example mine is:
/home/victor/.gem/ruby/1.8/bin
Check your path by typing
echo $PATH
It seens that when installing rubygems, now in ubuntu 9.04, I have this problem. I noticed that in "gem environment" the executable directory is "/var/lib/gems/1.8/bin", instead of "/usr/bin"... This is a problem with rubygems or with ubuntu 9.04??
The solution that I encountered is to add "/var/lib/gems/1.8/bin" to my $PATH doing this:
export PATH=$PATH:/var/lib/gems/1.8/bin
But it don't is saved... how can I save my path?
Thanks...
Resolvi: coloquei o export PATH=$PATH:/var/lib/gems/1.8/bin no ~/.bashrc! =]
mkmf is part of the ruby1.9.1-dev package. This package contains the header files needed for extension libraries for Ruby 1.9.1. You need to install the ruby1.9.1-dev package by doing:
sudo apt-get install ruby1.9.1-dev