I need to run a bunch of ruby scripts that I have written on a server that I don't have sudo access to.
On my own machine, I have installed a bunch of gems using 'sudo gem install ..' and used them in my code..
Is there any mechanism which would let me use these gems without formally installing them on a remote machine?
The basic difference is a gem is something that needs to be installed on the system running your Rails application, whereas a plugin is deployed along with your application. More specifically, plugins live in vendor/plugins whereas gems need to be install using rake gem install gem_name.
Using gem search -r , you can search RubyGems' repository. For instance, gem search -r rails will return a list of Rails-related gems. With the --local ( -l ) option, you would perform a local search through your installed gems.
A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .
You can, but it's tricky.
First, install them using the --install-dir
option, i.e.:
gem install gem_name --install-dir /some/directory/you/can/write/to
Second, make sure you have a .gemrc
file in your home directory that looks something like this:
gemhome: /some/directory/you/can/write/to
gempath:
- /some/directory/you/can/write/to
- /usr/local/lib/ruby/gems/1.8
gemhome
is where gems should look first when seeking a gem. gempath
is all the paths it should check in when seeking a gem. So in the .gemrc
above, I'm telling my code to look first in the local directory, and if not found, check the system gem directory.
Third, be aware that some code - even code within gems - can make assumptions about where gems are located. Some code may programmatically alter gempath
or gemhome
. You may need to "alter it back" in your own code.
There's not a lot (read: no) documentation on how to do that - the best way to figure it out is to read the tests that are included with the RubyGems source. Here's how I hack the gem paths in a rake task to point to my frozen version of capistrano:
Gem.use_paths(Gem.dir, ["#{RAILS_ROOT}/vendor/gems"])
Gem.refresh # picks up path changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With