Can anyone help with an odd Ruby Gem problem I'm having - note I've installed many gems in the past and never seen this.
I've downloaded the net-ssh and net-sftp gems using the following commands:
sudo gem install net-ssh
sudo gem install net-sftp
both installed successfully. However when I reference the files within my code I get the following error:
./workers/ffmpeg_worker.rb:6:in `require': no such file to load -- net/ssh (LoadError)
from ./workers/ffmpeg_worker.rb:6
from ./workers/tests/test_ffmpeg_worker.rb:3:in `require'
from ./workers/tests/test_ffmpeg_worker.rb:3
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
rake aborted!
Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]
Note when I do:
gem list --local
The gems are listed as such:
net-scp (1.0.2)
net-sftp (2.0.2, 1.1.0)
net-ssh (2.0.15, 1.1.2)
net-ssh-gateway (1.0.1)
Any clues?
When I see this sort of thing, it usually comes down to having more than one Ruby installed on the machine (which means more than one gem location, etc.), and different apps or environments getting confused about which one to load.
Check for that first. If that isn't the answer, do a gem which net/ssh to see where RubyGems thinks the gem is installed -- make sure it isn't the local user's .gems directory or something.
If neither one solves the mystery, stick some debugging code into your worker script and have it output its load path ($:) so you can see where it's looking.
Related
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.
I am trying to install Redmine to a Windows Server 2012, following "How to MANUALLY install Redmine 3.x on Windows Server 2008 R2".
After installing http://rubyinstaller.org/downloads/ the next step is to install Bundler but I got the following error:
C:\inetpub\wwwroot\redmine>ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
C:\inetpub\wwwroot\redmine>gem list
*** LOCAL GEMS ***
bigdecimal (1.2.6)
io-console (0.4.3)
json (1.8.1)
minitest (5.4.3)
power_assert (0.2.2)
psych (2.0.8)
rake (10.4.2)
rdoc (4.2.0)
test-unit (3.0.8)
C:\inetpub\wwwroot\redmine>gem install bundler
ERROR: While executing gem ... (Errno::EADDRNOTAVAIL)
The requested address is not valid in its context. - connect(2) for "0.0.0.0
" port 53
C:\inetpub\wwwroot\redmine>
Any help would be appreciated.
Check your DNS is right.
If your DNS not set, gem will display below error:
ERROR: While executing gem … (Errno::EADDRNOTAVAIL)
The requested address is not valid in its context. – connect(2) for “0.0.0.0″ port 53
Found it! You need to install a loopback adapter on Windows. There's lots of guides on how to do it. One of the first links on DuckDuckGo is that.
After poking around with ruby I noticed that uninstalling and reinstalling ruby does not remove some configs. I found a command:
gem env
This gave me the location of the configuration files. After completely deleting the directory .gem it started to work! Looks like something messed up my gem config and the defaults are right.
Start Command prompt with Ruby
Use command: gem env
Check GEM PATHS and locate directory .gem
Delete .gem directory
Done
Good luck!
I have ruby project and I installed all gems using 'bundle install'. Gems was installed in ./vendor/bundle. But I use ruby installed by rvm in another directory and when I try to do something (some command) It is looking for gems in rvm directory. How to install all gems in rvm directory?
Edit:
I installed all gems but when I tried to user simple ruby -T I get:
/home/arkency/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:298:in `to_specs': Could not find 'rake' (>= 0) among 1 total gem(s) (Gem::LoadError)
from /home/arkency/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:309:in `to_spec'
from /home/arkency/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:53:in `gem'
from /home/arkency/.rvm/gems/ruby-1.9.3-p545/bin/rake:22:in `<main>'
from /home/arkency/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `eval'
from /home/arkency/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `<main>'
My gem list contain only:
gem list
*** LOCAL GEMS ***
bundler (1.6.2)
By default, bundler installs gems to the system gem store. However, it has an optional configuration setting to install gems into another directory (in your case vendor/bundle). These gems are then only available in the specific bundler context.
You can force bundler to install the gems into the system gem store by running
bundle install --system
thus making them available to your global ruby installation.
This is necessary as bundler remembers certain options (e.g. the path where to install gems to) in the .bundle directory besides your Gemfile.
I know I have ruby and gem installed because I've installed a bunch of gems previously. Additionally when I do the following
~$ ruby --version
ruby 1.8.7 (2010-08-16 patchlevel 302 [i486-linux]
~$ gem --version
1.3.7
They, as you can see, return the version--yet when I try to do this--
~$ sass --watch happy.scss:happy.css
bash: sass: command not found
I'm a relative noob to everything, but far more to ruby and gems. For the sake of revealing more or less my level of understanding things generally I've learned enough of Debian to get a an environment where I could get Clojure running and get a web app working (taken me almost a year of spare time to do that--I knew virtually nothing of programming previoiusly). I'm trying to get sass working to ease my mental load in the webpage design side of things and I'm just hitting a brick wall on this.
Would this be a PATH issue? If so what needs to be on the path so that one gem works --
BTW here's what happens when I install sass--
# gem install sass
Successfully installed sass-3.2.5
1 gem installed
Installing ri documentation for sass-3.2.5...
Installing RDoc documentation for sass-3.2.5...
Any help anyone can give will be much appreciated. I've been at this one all day and can't figure it out for the life of me.
justin ⮀ ~ ⮀ gem install sass
Fetching: sass-3.2.5.gem (100%)
Successfully installed sass-3.2.5
1 gem installed
justin ⮀ ~ ⮀ sass -v
Sass 3.2.5 (Media Mark)
seems ok to me. I would check your path.
The proper PATH would depend on where your gems get installed. I use RVM so it will be different. You could try to throw an exception in your ruby code with rubygems loaded this should give you a starting point.
> rails c
Loading development environment (Rails 3.2.11)
1.9.3p362 :001 > throw test
ArgumentError: wrong number of arguments (0 for 2..3)
from (irb):1:in `test'
from (irb):1
from /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
so from that i see /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands/console.rb
so my bin path is at /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/bin
and if i
> ls /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/bin
b2json capify fog html2haml nokogiri rails ri sass-convert therubyracer tilt
bundle coderay geocode httpclient oauth rake2thor ruby_noexec_wrapper scss thin tt
cap erubis haml j2bson rackup rdoc sass sprockets thor
boom sass
so in my case I would want to add /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/bin
but i use RVM so it does that for me.
I'm on Ubuntu, and I've done
install gem mongo
which reported
Successfully installed bson-1.0
Successfully installed mongo-1.0
2 gems installed
I've started mongod
Now I cd to the mongo gem directory and try
> ruby examples/simple.rb
and I get the error
./examples/../lib/mongo.rb:31:in `require': no such file to load -- bson (LoadError)
from ./examples/../lib/mongo.rb:31
from examples/simple.rb:3:in `require'
from examples/simple.rb:3
which I can't make sense of, since the bson gem is installed
> gem list
*** LOCAL GEMS ***
bson (1.0)
bson_ext (1.0)
mongo (1.0)
rack (1.1.0)
sinatra (1.0)
Any suggestions what's up here?
The example script doesn't require rubygems, which means that bson isn't going to be in your load path. If you add
require 'rubygems'
to the start of the script, I believe it will work.