How to modify a Ruby gem
You can gem unpack
it, add your modification, then modify the gemspec if necessary and build it again:
- gem unpack
- gem build
How to change the path where ruby gems are installed on OS 10.6.6 Ruby 1.8 and Rails 3
I would suggest using RVM (Ruby Version Manager) to control which version of Ruby you are installing your gems into. It will also help keep all the bundle and gem data in a folder in your home directory.
Is there a way to make a private Ruby gem w/out having to set up a server?
You can always just reference a gem in a Gemfile
using a direct path, eg:
gem 'extracted_library', :path => './vendor/extracted_library'
You can also use a git archive. See the Gemfile docs for more details.This may help with your situation (I'm not sure of your exact setup).
Change default source when execute rails new?
A possible solution for project that use bundler
& Gemfile
is:
gem install bundler
bundle config mirror.https://rubygems.org https://gems.ruby-china.com
Add more mirrors, so that don't have to modify Gemfile's source, for each new project.
The additional mirror will be used if the default one is too slow or can't connect.
- If some package still stuck, then might need to:
- Edit
Gemfile
by hand, with best source in you region.
e.g:source https://gems.ruby-china.com
- Then run
bundle install
.
- Edit
Force RubyGems to use HTTP
The .gemrc
is not applied because it lives in your user directory but when you execute the command with sudo
the ownership of the execution is halted.
Either do not use sudo or use
$ sudo gem sources
to manage the sources.Usage: gem sources [options]
Options:
-a, --add SOURCE_URI Add source
-l, --list List sources
-r, --remove SOURCE_URI Remove source
-c, --clear-all Remove all sources (clear the cache)
-u, --update Update source cache
The command$ sudo gem sources -c
$ sudo gem sources -a http://rubygems.org/
should change the source list.Please keep in mind that if you are using rvm, bundler or rbenv, it's likely you don't need sudo
to install your gems.
How to find where gem files are installed
Use gem environment
to find out about your gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 2.1.5
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin12.4.0]
- INSTALLATION DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /Users/ttm/.rbenv/versions/2.0.0-p247/bin/ruby
- EXECUTABLE DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- SPEC CACHE DIRECTORY: /Users/ttm/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-12
- GEM PATHS:
- /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- /Users/ttm/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- /Users/ttm/.rbenv/libexec
- /Users/ttm/.rbenv/plugins/ruby-build/bin
- /Users/ttm/perl5/perlbrew/bin
- /Users/ttm/perl5/perlbrew/perls/perl-5.18.1/bin
- /Users/ttm/.pyenv/shims
- /Users/ttm/.pyenv/bin
- /Users/ttm/.rbenv/shims
- /Users/ttm/.rbenv/bin
- /Users/ttm/bin
- /usr/local/mysql-5.6.12-osx10.7-x86_64/bin
- /Users/ttm/libsmi/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/bin
Notice the two sections for:INSTALLATION DIRECTORY
GEM PATHS
gem cannot access rubygems.org
api.rubygems.org
is currently experiencing issues with IPv6 setup: this hostname has 4 IPv6 addresses, but responds on neither of them. Neither to ping
, nor to TCP connection attempts. When you are running gem
, your gem
tries IPv6 addresses first and times out on them, not having time to even try IPv4 addresses.
The solution is to lower priority of IPv6 addresses for api.rubygems.org
, so that gem
will try IPv4 addresses first. In order to do it, put these lines into /etc/gai.conf
:
# Debian defaults.
precedence ::1/128 50
precedence ::/0 40
precedence 2002::/16 30
precedence ::/96 20
precedence ::ffff:0:0/96 10
# Low precedence for api.rubygems.org IPv6 addresses.
precedence 2a04:4e42::0/32 5
Related Topics
Why Does Including This Module Not Override a Dynamically-Generated Method
If I Have a Stripe Token from a Charge, How to Get Its Charge Id
What Is Returned in Ruby If The Last Statement Evaluated Is an If Statement
Set Ruby 2.0 Keyword Arguments with Attr_Accessor on Initialize
How to Click on Specific Element in Canvas by Its Coordinates (Using Webdriver)
How to Remove Header and Footer from Some of The Pages in Ruby on Rails
Starting with Redmine Locally - How Easy Is Migration to Server Later
Converting Ruby Hashes to Arrays
Error Generating Source Map - Grunt and SASS Configuration
Ruby: Parse Excel 95-2003 Files
Rvm - Macports Won't Update Through Proxy
How to Make Http Delete Request in My Ruby Code Using Net::Http
How to Update All of My Products to a Specific User When Seeding