Reputation: 125912
I'm trying to set up a Sinatra app on my web host. I don't have sudo rights to install gems in the system-wide path, which is several subfolders beneath /usr/local
, but I do have a gems
folder in my app's directory.
This reference gives the following definitions:
GEM_HOME
- "Directory containing the master gem repository."GEM_PATH
- "Path list of directories containing gem repositories to be searched in addition to the GEM_HOME directory. The list should be delimited by the appropriate path separator (e.g. ‘:’ on Unix and ‘;’ on Windows)"When I first ssh into this web host, echo $GEM_HOME
and echo $GEM_PATH
both produce an empty string, but gem list
shows several gems.
From the command line, I have set GEM_HOME
like this:
GEM_HOME=$PWD/gems # 'gems' folder under present working directory
echo $GEM_HOME # correctly outputs the gem folder I specified
ls $GEM_HOME # shows gems folder contents, namely:
# bin/ cache/ docs/ gems/ specifications/
I also set GEM_PATH
to the same folder.
After doing this, gem list
still shows global gems rather than the gems in the specified folder, and gem install
still tries to install to the global location.
What am I missing?
Upvotes: 1
Views: 1641
Reputation: 21700
There is no manpage for gem
, which doesn't make it easier. I assume GEM_PATH
is where to look for the gems, and GEM_HOME
is where to install them. Try
export GEM_HOME = "$GEM_PATH"
Upvotes: 2
Reputation: 125912
Looks like export
, as Tass showed, was the missing piece: it makes my local GEM_HOME
variable a global one.
Here's what I've done:
export GEM_HOME=$PWD/gems # where to install and look for gems
export PATH=$PWD/gems/bin:$PATH # append the gems' binaries folder to
# the current path, so that I can call
# `bundle install` and have it find
# myapp/gems/bin/bundle
Upvotes: 2
Reputation: 4879
You could use Bundler as well. Bundler makes it very easy to manage Gem versions, even when sudo access is not possible. You create a file called Gemfile
in the root of your application and put lines such as these:
gem "sinatra"
gem "some_other_gem_dependency"
gem "and_so_on_and_so_forth", ">= 1.0"
And then run bundle install --path /where/you/want/your/gems/stored
which will install the gems to a path you have access to. You then put this in your config.ru:
require 'rubygems'
require 'bundler'
Bundler.require
require './your_app'
run YourApp
Check out http://gembundler.com/sinatra.html for more info.
Upvotes: 1