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.
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:
rack (2.2.5) - Source
rackup (0.2.3) - Source
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 called Gemfile:
# 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.
Related
Something strange is happening, everything used to work fine a few hours ago.
I have a private gem as dependency to a project. I've added the private gem git repo as follows:
gem 'my-awesome-gem', '>=1.2.3', git: 'https://john:pass123#bitbucket.org/johndoe/my-awesome-gem'
When doing bundle install it shows:
...
Using my-awesome-gem 1.2.3 from https://john:pass123#bitbucket.org/johndoe/my-awesome-gem (at master#bc19e27)
Bundle complete! 5 Gemfile dependencies, 21 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
But this gem doesn't show when I do gem list. Also, when I do pry -r my-awesome-gem or require it in the project it returns:
! Unable to load application: LoadError: cannot load such file -- my-awesome-gem
/Users/johndoe/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- my-awesome-gem (LoadError)
...
I've been playing around for a few hours but can't find the problem. I've tried reinstalling ruby via rbenv. I'm using Ruby 2.4.1 via rbenv.
What am I doing wrong?
When using Bundler you must engage Bundler in any code you use. That means either:
require 'bundler/setup'
require 'my-awesome-gem'
Or:
pry -r bundler/setup -r my-awesome-gem
The gem is installed, it's just not in your $LOAD_PATH until you get Bundler to load in the Gemfile and find all the dependencies.
I'm working on a jekyll site on Ubuntu 15.04 and when i try jekyll serve (or any other jekyll command, with or without sudo) i receive the following:
/var/lib/gems/2.1.0/gems/jekyll-3.1.2/bin/jekyll:9:in `<top (required)>': undefined method `require_from_bundler' for Jekyll::PluginManager:Class (NoMethodError)
from /usr/local/bin/jekyll:23:in `load'
from /usr/local/bin/jekyll:23:in `<main>'
I have worked on jekyll sites on this computer recently without this issue, and I'm not certain how the configuration changed to generate this error. I've tried gem uninstall jekyll and reinstalling it, same issue happens. I'm not a Ruby dev and I'm a bit at a loss for how to troubleshoot this.
Well, I suggest you to run Jekyll with Bundler, which is an awesome dependency manager. It will make sure you have all the gems you need.
1st. Uninstall Jekyll 2.2.0. This version is too old and requires Python to run some dependencies. Jekyll 3.x does not require Python anymore.
So, run sudo gem uninstall jekyll --version 2.2.0. (or gem uninstall jekyll -v 2.2.0)
2nd. Now, install Bundler:
gem install bundler (or sudo gem install bundler)
3rd. Add a Gemfile (don't give it any extension) to your site root with the following content:
source "https://rubygems.org"
gem 'jekyll', '3.1.2'
This will make sure you will have installed Jekyll 3.1.2 and all its dependencies.
If you will deploy your site to GitHub, the Gemfile must be different:
source "https://rubygems.org"
gem 'github-pages'
This will include the Jekyll version running at GitHub pages at the time.
4th. Using the terminal, cd path/to/path to your site root and run bundle install there. Bundler will install all the dependencies for you and create a new file called Gemfile.lock, which will have a list of all dependencies installed for that project.
5th. Run bundle exec jekyll serve
Done!
NOTE 1: I recommend you to use Jekyll 3.0.3, as I think it's better then 3.1.2 (it seems there are some bugs on 3.1.2 which don't have in 3.0.3). Anyway, opinion based tip - it's up to you.
NOTE 2: If you don't have openssl installed to your computer, replace the protocol in your Gemfile:
source "https://rubygems.org"
replace for
source "http://rubygems.org"
For reference:
Jekyll 2x-to-3x
Jekyll on GitHub
That's it! Hope to have helped!
I am beginner in ruby and wanted to install and GUI toolkit. So i surfed web and found shoes was one toolkit so i downloaded the ".install" file it didn't work saying some permission error, then i downloaded the older version which was ".run" format and that too didn't work so i found a gem of shoes when i try to download i get the below in ruby. i downloaded this shoes from git and still facing some error.
root#Drona:/home/naren/shoes4# gem install bundler && bundle install
Successfully installed bundler-1.10.5
1 gem installed
Installing ri documentation for bundler-1.10.5...
Installing RDoc documentation for bundler-1.10.5...
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all
non-root users on this machine.
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies....
Using rake 10.4.2
Using addressable 2.3.8
Using after_do 0.3.1
Using ast 2.0.0
Using parser 2.2.2.6
Using astrolabe 1.3.0
Using benchmark-ips 2.2.0
Using bouncy-castle-java 1.5.0147
Using docile 1.1.5
Installing json 1.8.3 with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:1:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.
the above is the terminal output.
Ruby version installed is :
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
someone help we out with this installation
and if i have done anything wrong in installation of shoes then let me know
From your terminal directory it seems like you are trying to install shoes4 on ruby 1.9.3. To install shoes4 you need JRuby and a JDK - please follow the instructions in the readme
Shoes 3 can't be installed through gem install due to the way it was built. For Shoes 3 you need the install script, I recommend the appropriate Shoes 3.2 version from this page. If this fails with some error please let us know the error so we can help :)
You should use the gem program to install shoes. If on your command line you type gem install shoes you should be fine.
to use it in an app, you would need to create a Gemfile and run Bundle install within your folder
I just installed Koala on my Ubuntu 12.04 system. When I try to compile my .scss files, I get the following error message:
/home/tylerschade/loancalculator/style.scss
/usr/share/koala/bin/sass:4:in `require': no such file to load -- rubygems (LoadError)
from /usr/share/koala/bin/sass:4
What is wrong with it?
In Ruby < 1.9, the rubygems gem is not installed automatically. You need to install it manually before you use anything that depends on a gem.
In your system, do this:
sudo apt-get install rubygems
You may also have to write
require "rubygems"
somewhere in a Ruby file.
By the way, it is a bad idea to be using Ruby 1.8 at this time.
I keep getting an error when I run a file called wc.rb. I type:
ruby wc.rb
but I keep getting this error:
/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- nokogiri (LoadError)
from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from wc.rb:3:in `<main>'
However, it works when I run the same script with:
sudo ruby wc.rb
Is there anything I can do so that I don't have to run this script as a super user?
When you run with sudo are you running the same version of Ruby? If sudo ruby -v returns something different than ruby -v, you may have only installed the Nokogiri gem in the Ruby 2.0 gem location, and not for the gem location associated with your system's default version of Ruby.
Update: If you originally installed the Nokogiri gem using sudo, you also may need to uninstall it first using sudo (sudo gem uninstall nokogiri) and re-install it without using sudo (gem install nokogiri) for the permissions to be correct.