2

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 then sudo 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.

orblivion
  • 446
  • 3
  • 12
  • Check again - `rack` is not missing it got line wrapped. – orblivion Jan 12 '23 at 01:26
  • @engineersmnky I think I understood your comment, my reply may have been unclear. I did run `gem install sqlite3 cgi glug rack`, and I said so in my initial post. Look again, the word `rack` is there, it's just on the next line because of line wrapping. – orblivion Jan 12 '23 at 16:50
  • That was it, thanks! (At least the server starts up, no comment yet on if it runs correctly). You want to write this up as a solution so you get credit? Or I could edit the below answer. – orblivion Jan 12 '23 at 17:23

2 Answers2

3

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:

engineersmnky
  • 25,495
  • 2
  • 36
  • 52
  • Hmm, the downgrade works. The rackup solution seems to lead to a subsequent bug instead. But, I'll make a PR and point this answer to them and let them sort out what they want to do. Thanks. – orblivion Jan 12 '23 at 17:37
  • (er, not PR, I mean Github issue, on the tilemaker project) – orblivion Jan 12 '23 at 17:45
1

for a better setup under your user, this could be done:

  1. ensure to have ruby running under your user by:
ruby -v # 2.7 or higher is better
  1. then create a file besides your script server.rb called Gemfile:
# Gemfile
source "https://rubygems.org"

gem "rack"
gem "sqlite3"
gem "cgi"
gem "glug"
  1. 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.

  1. After installing you can call:
bundle install 
# will install all the gems needed and will lock the latest versions for you inside Gemfile.lock
  1. 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.

manuwell
  • 402
  • 2
  • 8
  • There is no such version as Ruby 2.8. https://www.ruby-lang.org/en/downloads/releases/ You probably meant 2.7 but this will soon be EOL. Recommend the latest version of Ruby, or at a minimum versions still under normal maintenance. – anothermh Jan 11 '23 at 22:05
  • it was a typo, lol. 2.7.7 will fit for the most project but for those gems who uses new feature languages it will break; to be certain, I would use 3.2.0 – manuwell Jan 11 '23 at 22:14
  • Seems like a more proper approach but I get the same error. If it's not obvious to you what I did wrong maybe it's actually a bug and I should report it. – orblivion Jan 12 '23 at 01:30