Ruby can't find installed gems windows 10 - ruby

When running a script containing the following
require 'rubygems'
require 'zip'
I am getting
`require': cannot load such file -- zip
First I have tried to install like this 'rubyzip'
gem install rubyzip
When looking at the gem env:
>gem env
RubyGems Environment:
RUBYGEMS VERSION: 2.4.8
RUBY VERSION: 2.2.3 (2016-01-26 patchlevel 0) [java]
INSTALLATION DIRECTORY: C:/jruby-9.0.5.0/lib/ruby/gems/shared
RUBY EXECUTABLE: C:/jruby-9.0.5.0/bin/jruby.exe
EXECUTABLE DIRECTORY: C:/jruby-9.0.5.0/bin
SPEC CACHE DIRECTORY: C:/Users/lucio/.gem/specs
SYSTEM CONFIGURATION DIRECTORY: C:/jruby-9.0.5.0/etc
RUBYGEMS PLATFORMS:
- ruby
- universal-java-1.8
GEM PATHS:
- C:/jruby-9.0.5.0/lib/ruby/gems/shared
- C:/Users/lucio/.gem/jruby/2.2.0
in the irb seems like the require works
irb(main):001:0> require 'zip'
=> true
I also trying to install with bundler after installing
>bundle show
Gems included by the bundle:
* bundler (1.12.4)
* rubyzip (1.2.0)
but when running my script I get
>bundler exec ruby zip.rb
Could not find rubyzip-1.2.0 in any of the sources
Run `bundle install` to install missing gems.
I can also see it in the gem list
>gem list -l
*** LOCAL GEMS ***
bundler (1.12.4)
jar-dependencies (0.2.3)
jruby-openssl (0.9.15 java)
jruby-win32ole (0.8.5)
json (1.8.0 java)
minitest (5.4.1)
power_assert (0.2.3)
psych (2.0.15 java)
racc (1.4.13 java)
rake (10.1.0)
rdoc (4.1.2)
rubygems-update (2.6.4)
rubyzip (1.2.0)
Can anybody help ?

Found the problem.
I had Jruby installed along with Ruby, so when installing the gem it will automatically install under the Jruby directory and later won't be found by Ruby removing the Jruby from PATH end variable solved the problem

Related

Error when running msfconsole in Pentestbox

In PENTESTBOX I want to run METASPLOIT-FRAMEWORK by running command msfconsole
and it is giving the following error ``
Bundler could not find compatible versions for gem "ruby ":
In Gemfile:
ruby x86-mingw32
metasploit-framework x86-mingw32 was resolved to 5.0.83, which depends on
ruby (>= 2.5) x86-mingw32
Could not find gem 'ruby (>= 2.5)', which is required by gem 'metasploit-framework', in any of the relevant sources:
the local ruby installation
To fix your issue run
gem install bundler -v 1.12
bundle _1.12_ install

Gem::InstallError: nokogiri requires Ruby version < 2.7.dev, >= 2.3 on Pentestbox

when I try to run metasploit on pentestbox last version I get the below error
could not find compatible versions for gem "activesupport": In snapshot (Gemfile.lock): activesupport (= 4.2.11) In Gemfile: metasploit-framework x86-mingw32 was resolved to 5.0.5, which depends on activerecord (~> 4.2.6) x86-mingw32 was resolved to 4.2.10, which depends on activesupport (= 4.2.10) x86-mingw32 rspec-rails x86-mingw32 was resolved to 3.8.2, which depends on railties (>= 3.0) was resolved to 4.2.11, which depends on activesupport (= 4.2.11) x86-mingw32 Running bundle update will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict.
I tried running the command "bundle update", but got this error
Fetching nokogiri 1.10.1 (x86-mingw32) Installing nokogiri 1.10.1 (x86-mingw32) Gem::InstallError: nokogiri requires Ruby version < 2.7.dev, >= 2.3. An error occurred while installing nokogiri (1.10.1), and Bundler cannot continue. Make sure that gem install nokogiri -v '1.10.1' succeeds before bundling
after that I try run command "bundle install" I get same Error
I also got the same error in my Windows 10 and I was able to install the nokogori successfully. Below is my Ruby environment.
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.5
- RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x64-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby222-x64/lib/ruby/gems/2.2.0
- RUBY EXECUTABLE: C:/Ruby222-x64/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby222-x64/bin
- SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
- RUBYGEMS PLATFORMS:
- ruby
- x64-mingw32
- GEM PATHS:
- C:/Ruby222-x64/lib/ruby/gems/2.2.0
To solved the issue I just updated my Gemfile. I added this line:
gem 'nokogiri', '~> 1.6.8'
I am using Windows 10, I installed nokogiri prerelease version in which this is fixed.
gem inst nokogiri --pre
Then I changed the dependency in the gemfile.lock file:
nokogiri (1.11.0.rc2-x64-mingw32)
Reference:
https://github.com/sparklemotion/nokogiri/issues/1961

Cannot run Jekyll new command

I tried to use Jekyll new command, but it didn't work and came out following errors.
$ jekyll new myblog
/Library/Ruby/Gems/1.8/gems/commander-4.1.6/lib/commander/runner.rb:385:in `require_program': program version required (Commander::Runner::CommandError)
from /Library/Ruby/Gems/1.8/gems/commander-4.1.6/lib/commander/runner.rb:384:in `each'
from /Library/Ruby/Gems/1.8/gems/commander-4.1.6/lib/commander/runner.rb:384:in `require_program'
from /Library/Ruby/Gems/1.8/gems/commander-4.1.6/lib/commander/runner.rb:52:in `run!'
from /Library/Ruby/Gems/1.8/gems/commander-4.1.6/lib/commander/delegates.rb:8:in `run!'
from /Library/Ruby/Gems/1.8/gems/commander-4.1.6/lib/commander/import.rb:10
from /usr/bin/jekyll:23
/Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require': no such file to load -- json (LoadError)
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/jekyll-1.4.3/bin/../lib/jekyll/filters.rb:2
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/jekyll-1.4.3/bin/../lib/jekyll.rb:44
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/jekyll-1.4.3/bin/jekyll:7
from /usr/bin/jekyll:23:in `load'
from /usr/bin/jekyll:23
I'm using Mac OS X 10.8.5 Mountain Lion.
I checked stackoverflow and found a post which has a similar problem.
Error when running jekyll new command
Then I tried the below command.
$ sudo gem install json
but It didn't work for my situation. I uninstalled and reinstalled json but nothing happened.
Please let me know if you know any other solutions. I've been stuck on this problem since the beginning of the week...
my gem list & gem environment are as follows.
$ gem list
*** LOCAL GEMS ***
bigdecimal (1.2.4)
blankslate (2.1.2.4)
classifier (1.3.4)
colorator (0.1)
commander (4.1.6)
fast-stemmer (1.0.2)
ffi (1.9.3)
highline (1.6.21)
io-console (0.4.2)
jekyll (1.4.3)
json (1.8.1)
liquid (2.5.5)
listen (1.3.1)
maruku (0.7.1)
minitest (4.7.5)
parslet (1.5.0)
posix-spawn (0.3.8)
psych (2.0.3)
pygments.rb (0.5.4)
rake (10.1.0)
rb-fsevent (0.9.4)
rb-inotify (0.9.3)
rb-kqueue (0.2.2)
rdoc (4.1.0)
redcarpet (2.3.0)
safe_yaml (0.9.7)
test-unit (2.1.1.0)
toml (0.1.1)
yajl-ruby (1.1.0)
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.2
- RUBY VERSION: 2.1.1 (2014-02-24 patchlevel 76) [x86_64-darwin12.0]
- INSTALLATION DIRECTORY: /usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0
- RUBY EXECUTABLE: /usr/local/Cellar/ruby/2.1.1/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/Cellar/ruby/2.1.1/bin
- SPEC CACHE DIRECTORY: /Users/MyName/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-12
- GEM PATHS:
- /usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0
- /Users/MyName/.gem/ruby/2.1.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /usr/local/bin
- /usr/local/sbin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/git/bin
- /Users/MyName/.rvm/bin
Please give me advice to help me. Thank you!
Updated on Mar 7.
$ rvm list
rvm rubies
# No rvm rubies installed yet. Try 'rvm help install'.
Just in case you would like to see Homebrew list,
$ brew list
autoconf gmp4 libtool openssl readline
automake libgpg-error libyaml pkg-config ruby
cloog-ppl015 libksba llvm ppl011 ruby-build
gcc46 libmpc08 mpfr2 rbenv
2nd updated on Mar 7.
$ which ruby
/usr/local/bin/ruby
$ which jekyll
/usr/bin/jekyll
$ ruby --version
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin12.0]
$ echo $PATH
/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Users/MyName/.rvm/bin
I remember that my mac had been installed Ruby 1.8.7 before I installed 2.1.1p76.
It looks like you have multiple versions of Ruby on your system (1.8.7 and 2.1.1), which is very common, and part of the reason tools like rvm and rbenv were created. The issue is that when you did gem install jekyll (maybe with a sudo) and sudo gem install json, these seem to have ended up in different spots and aren't finding each other. The /usr/local/bin location is typically where Homebrew puts things (hence, you have ruby listed under brew list) and this is your Ruby 2.1.1 location. However, your jekyll installation is under the location of the Apple-installed Ruby 1.8.7.
Step 1: try gem uninstall jekyll, then gem install jekyll. This should fix your problems.
Step 2: If that doesn't work, try to use rbenv or rvm to select a different version of Ruby, then try Step 1 again.
For example, my installations are here (managed via rvm):
$ which jekyll
/Users/nicksuch/.rvm/gems/ruby-2.0.0-p247/bin/jekyll
$ which gem
/Users/nicksuch/.rvm/rubies/ruby-2.0.0-p247/bin/gem
$ which ruby
/Users/nicksuch/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
In my case the Jekyll template suggested to use bundle utility as:
bundle exec jekyll build
The solution was to include json into Gemfile (which was already part of the sources):
diff --git a/Gemfile b/Gemfile
index 98b29af..b8537cf 100644
--- a/Gemfile
+++ b/Gemfile
## -1,7 +1,8 ##
source "https://rubygems.org"
+gem "json"
gem "jekyll", "~> 3.0"
gem "jekyll-sitemap"
DETAILS
What lead me to the solution was the following fact:
command gem list json showed json gem installed;
but command bundle exec gem list json didn't show anything.
I also tried to run bundle exec gem install json - it didn't work. My best guess was that bundle sets up the environment for a single run based on Gemfile which is the only way to make set of dependencies persistent across each bundle exec ... executions.

gem install error--Ruby version >=1.9.3 required

I have been attempting to install the httparty gem, but the install fails with:
Error installing httparty:
httparty requires Ruby version >=1.9.3
My ruby version, from running ruby -v, is 1.9.3p448
Running gem env yields:
RUBYGEMS VERSION: 2.0.7
RUBY VERSION: 1.9.3
INSTALLATION DIRECTORY: .../ruby 1.9.3-p448/bin/ruby
RUBY EXECUTABLE: .../ruby-1.9.3-p448/bin
GEM PATHS:
.../gems/ruby-1.9.3-p448
.../ruby-1.8.3-p448#global
Any ideas why this is failing & what i can to to fix it, short of manually editing the gem to remove the 1.9.3 requirement?
This seems to me like it isn't using Ruby 1.9.3 as that is exactly what the error says. I had the same error message today when pushing to Heroku:
Installing httparty (0.12.0)
Gem::InstallError: httparty requires Ruby version >= 1.9.3.
An error occurred while installing httparty (0.12.0), and Bundler cannot
continue.
Make sure that `gem install httparty -v '0.12.0'` succeeds before bundling.
I just added
ruby '1.9.3'
to the top of my Gemfile like so:
source 'http://rubygems.org'
ruby '1.9.3'
gem 'rails', '3.0.20'
and all is well.

Ruby yob pdf reader, wrong argument quantity

I'm trying to install the yob pdf reader: https://github.com/yob/pdf-reader#readme
My script has the following code:
reader = PDF::Reader.new("1.pdf")
when I run that script I get the following error:
`initialize': wrong number of arguments (1 for 0) (ArgumentError)
Which doesn't make any sense because the directions say this should be done this way.
How do I solve this?
p.s.
gem list command produces:
*** LOCAL GEMS ***
Ascii85 (1.0.1)
bundler (1.0.18)
columnize (0.3.4)
linecache (0.46)
nokogiri (1.5.0)
pdf-reader (0.10.0)
rbx-require-relative (0.0.5)
rdoc (3.9.4, 2.5.11)
rdoc-data (2.5.3)
ruby-debug (0.10.4)
ruby-debug-base (0.10.4)
rudebug (0.3.2)
syntax (1.0.0)
gem -v produces: 1.3.7
You most likely have a gem version conflict. You can specify the version of the gem that you want to require, in case you have multiple versions installed:
require 'rubygems'
gem 'pdf-reader', "~> 0.10.0"
require 'pdf-reader'
Update
I would slap myself if I could. There's nothing wrong with your setup. The instructions to use PDF::Reader.new "my_file.pdf" are for the git version.
Check the examples directory for the version 0.10.0 to get examples of how to use the library.

Resources