I'm not a Ruby person, so this may be a 101 question. I'm just trying to use a utility that happens to be written in Ruby.
I'm using tilemaker, a utility in the openstreetmap ecosystem. It creates tiles in the mbtiles format. The repository comes with a simple utility to serve the tiles on a browser to test the files you create. This utility is written in Ruby, and is what I'm having trouble with.
The repo's README has instructions for the server utility. The installation instructions read:
(If you don't already have them, you'll need to install Ruby and the required gems to run the demonstration server. On Ubuntu, for example,
sudo apt install sqlite3 libsqlite3-dev ruby ruby-dev
and thensudo gem install sqlite3 cgi glug rack
.)
I'm on Debian 11 (on Qubes, so I don't mind running sudo gem install as they recommend). I hope this is close enough to Ubuntu but maybe this is related to the problem.
This is what I get:
$ ruby server.rb ~/countries-raster.mbtiles
Starting local server
Traceback (most recent call last):
3: from server.rb:22:in `<main>'
2: from server.rb:118:in `<class:MapServer>'
1: from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in `require'
/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- rack/handler (LoadError)
What am I missing here? Thanks.
CodePudding user response:
It appears that the issue is that you are using a 3.X release of rack
.
According to the CHANGELOG as of version 3.0 Rack::Handler
was removed from rack
and pulled out into its own gem (rackup
).
To resolve the issue you will need to either use an older version of rack
gem 'rack', '~> 2.2'
Or you will need to add the rackup gem as a dependency:
gem 'rack'
gem 'rackup'
Either option will provide access to rack/handler
:
CodePudding user response:
for a better setup under your user, this could be done:
- ensure to have ruby running under your user by:
ruby -v # 2.7 or higher is better
- then create a file besides your script
server.rb
calledGemfile
:
# Gemfile
source "https://rubygems.org"
gem "rack"
gem "sqlite3"
gem "cgi"
gem "glug"
- After that, ensure to have
bundler
installed (this is a gem to manage gem versioning), by:
gem install bundler
If you face a permission error, is because your ruby
program is under root
user. So you can use via sudo bundle install
, but anything else must be run under sudo
, or you can install and setup rvm which will install and configure ruby
under your user.
- After installing you can call:
bundle install
# will install all the gems needed and will lock the latest versions for you inside Gemfile.lock
- run your server by:
bundle exec ruby server.rb
by running via bundle exec
your telling to ruby to use the gems installed and versioned by the Gemfile.lock
. This guarantees to your software to require the specific versions and avoid collisions or anything else.