RGeo::Geos.supported? shows as false even with -dev packages and symlink in place - rgeo

Trying to get the rgeo gem to recognise geos on an ubuntu 16.04 system.
I have the following packages installed:-
libgeos-dev, libgeos++-dev and libgeos-3.7.1
geos-config --version
3.7.1
I have a symlink in /usr/lib which points to the location of the version specific version in
lrwxrwxrwx 1 root root 42 Oct 21 18:05 libgeos.so -> /usr/lib/x86_64-linux-gnu/libgeos-3.7.1.so
Have run the following commands
gem uninstall rgeo
gem install rgeo -- --with-geos-dir=/usr/lib
However when I run the following it fails
RAILS_ENV=staging bundle exec irb
require 'rgeo'
RGeo::Geos.supported?
=> false
What am I doing wrong? Have searched the various posts about this which has led me to install the -dev package and create the symlink, but still it doesnt work.
Have also added /usr/lib to /etc/ld.so.conf.d/ and run ldconfig but without success.
Update
RAILS_ENV=staging bundle exec irb
2.5.0 :001 > require 'rgeo'
=> true
2.5.0 :002 > RGeo::Geos.supported?
=> true
2.5.0 :003 >
shows it working, but
Loading staging environment (Rails 5.2.0)
2.5.0 :001 > require 'rgeo'
=> false
2.5.0 :002 > RGeo::Geos.supported?
=> false
fails
and the app still shows
RGeo::Error::RGeoError (GEOS is not available, but is required for correct interpretation of polygons in shapefiles.)

spring stop and restarting rails console fixed it for me.

To fix that on CircleCi I needed to run these commands on ubuntu machine, then re-install rgeo gem
sudo apt update
sudo apt install libgeos++-dev libgeos-3.8.0 libgeos-c1v5 libgeos-dev libgeos-doc
gem unintsall rgeo
gem install rgeo

Related

Ruby Not Requiring C Extension

I have a gem I published a while ago that I'm trying to upgrade (https://github.com/fny/xorcist). Right now I'm wrestling with a require issue that I haven't seen before. I'm following the same instructions I have from prior updates.
git clone https://github.com/fny/xorcist && cd xorcist
rbenv install 3.1.2
rbenv shell 3.1.2
rake test
#=> ~/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in
`require': cannot load such file -- xorcist/xorcist (LoadError)
This is strange. It looks like xorcist loads perfectly, but the C extension does not, which is where require 'xorcist/xorcist' refers.
If you just run rake, it runs both the compile and then the test task.
task :default => [:compile, :test]

Capistrano using Ruby 1.8 instead of 1.9.3

I'm having a really strange issue. On my remote server (which is a Max OSX Server), I have Ruby 1.9.3 installed via RVM. When I type ruby -v, I get
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.3.0]
When I type in which bundle, I get
/Users/moby/.rvm/gems/ruby-1.9.3-p448/bin/bundle
And if I do bundle install in my Rails project, it succeeds without any errors.
However, when I try with Capistrano via cap deploy:cold on my local machine, which SSH's into the remote machine, deployment fails with the following error:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:777:in
`report_activate_error': Could not find RubyGem bundler (>= 0)
(Gem::LoadError)
Why is it using Ruby 1.8? How do I get it to use Ruby 1.9.3 instead?
I was able to solve the issue by doing the following:
SSH into your remote server, and print out the following values:
$PATH
$RUBY_VERSION
$GEM_HOME
$GEM_PATH
$BUNDLE_PATH
Add the following entry into the deploy.rb file, setting the values of each key to the respective outputs from above:
set :default_environment, {
'PATH' => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448/bin:/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/USERNAME/.rvm/rubies/ruby-1.9.3-p448/bin:/Users/USERNAME/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/usr/local/git/bin",
"RUBY_VERSION" => "ruby 1.9.3",
"GEM_HOME" => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448",
"GEM_PATH" => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448:/Users/OraServer1Admin/.rvm/gems/ruby-1.9.3-p448#global",
"BUNDLE_PATH" => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448/bin/bundle"
}
sudo update-alternatives --config gem
and select the right version

bundle package fails when run inside rake task

My Environment
Vanilla Ubuntu 12.10, no rvm or renv.
> gem --version
1.8.23
> ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
> bundle --version
Bundler version 1.2.1
My problem
I have a rake task to package my gems and upload them to my development and production servers. The problem is that the rake task fails when the Gemfile includes git or path gems. Bundler already supports packaging of these type of gems and it works great on my terminal but it fails when running withing a rake task and I cannot find out why.
My rake task
> cat lib/tasks/upload.rake
namespace :deploy do
desc "Package all gems and upload to remote server"
task :upload => [:environment] do |t, args|
if ! system("bundle package --all")
raise "TOTAL FAIL"
end
# Magic method to upload vendor/cache to remote server
end
end
My tries
Running bundle package in the terminal works:
> bundle package --all
....
Using bson (1.7.0)
Using bson_ext (1.7.0)
Using cancan (1.6.8) from git://github.com/ryanb/cancan.git (at /home/ryujin/Projects/rails/Encluster4/vendor/cache/cancan-4dcd54459482)
Using carrierwave (0.7.0)
Using coffee-script-source (1.4.0)
....
Updating files in vendor/cache
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Updating files in vendor/cache
Running bundle package withing irb also works:
> irb
irb> system("bundle package --all")
...
Using ansi (1.4.3)
Using bson (1.7.0)
Using bson_ext (1.7.0)
Using cancan (1.6.8) from git://github.com/ryanb/cancan.git (at /home/ryujin/Projects/rails/Encluster4/vendor/cache/cancan-4dcd54459482)
Using carrierwave (0.7.0)
Using coffee-script-source (1.4.0)
...
Updating files in vendor/cache
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Updating files in vendor/cache
=> true
But bundle package does not work when executed within my simple rake task:
> bundle exec rake deploy:upload
Updating files in vendor/cache
Could not find cancan-1.6.8.gem for installation
rake aborted!
TOTAL FAIL
Tasks: TOP => deploy:upload
(See full trace by running task with --trace)
I find not reason why this could fail. I am running in the same environment all the time. I already checked the bundle exec file is the same (/usr/local/bin/bundle) on all three cases. I have no traces or rvm or renv or anything like that. Also tried running the task without bundle exec and the same problem.
Thanks in advance for any tips on why this happens.
I had the same trouble.
I checked the environment variables and find out that the bundler modifies RUBYOPT:
$ bundle exec env > benv.txt
$ env > env.txt
$ diff -u env.txt benv.txt
--- env.txt 2012-12-05 17:13:10.000000000 +0400
+++ benv.txt 2012-12-05 17:13:07.000000000 +0400
## -72,4 +72,8 ##
CDPATH=.
install_flag=1
rvm_hook=
-_=/usr/bin/env
+_=/Users/denis/.rvm/gems/ruby-1.9.3-p327#global/bin/bundle
+_ORIGINAL_GEM_PATH=/Users/denis/.rvm/gems/ruby-1.9.3-p327:/Users/denis/.rvm/gems/ruby-1.9.3-p327#global
+BUNDLE_BIN_PATH=/Users/denis/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/bin/bundle
+BUNDLE_GEMFILE=/Users/denis/src/my-project/Gemfile
+RUBYOPT=-I/Users/denis/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib -rbundler/setup
So, to workaround I do this:
system %Q(/usr/bin/env RUBYOPT= bundle package)
Hope this helps!
One can also prefer to use
Bundler.with_clean_env do
sh "bundle update --source .."
end
and indeed it is an RUBYOPT problem as mentioned by Denis

Graphene: ruby bundler install fails

I installed the latest graphene from github in /opt/graphene on my Debian 6.0 linux server. I am trying to code up a graphite dashboard with graphene, but I'm having problems with ruby's bundler
As I follow the github markdown README.md, I successfully installed the ruby debian package as well as rubygems.
Next, I sudo gem install serve with no problems.
I can surf to the example site on port 4000, so I know that ruby and rubygems are working...
Next, I install bundler with sudo gem install bundler as required by graphene's README; However, when I take the next step in README.md, bundle install fails...
[mpenning#tsunami graphene]$ sudo /var/lib/gems/1.8/gems/bundler-1.2.0/bin/bundle install
[sudo] password for mpenning:
/var/lib/gems/1.8/gems/bundler-1.2.0/bin/bundle:2:in `require': no such file to load -- bundler (LoadError)
from /var/lib/gems/1.8/gems/bundler-1.2.0/bin/bundle:2
[mpenning#tsunami graphene]$
I'm not completely ignorant of ruby, but it's confusing why this fails at line 2
[mpenning#tsunami graphene]$ sudo head /var/lib/gems/1.8/gems/bundler-1.2.0/bin/bundle
#!/usr/bin/env ruby
require 'bundler'
# Check if an older version of bundler is installed
$:.each do |path|
if path =~ %r'/bundler-0.(\d+)' && $1.to_i < 9
err = "Please remove Bundler 0.8 versions."
err << "This can be done by running `gem cleanup bundler`."
abort(err)
end
end
[mpenning#tsunami graphene]$
It's self-evident that bundler is installed. My ruby-fu is weak, but it doesn't make sense to me that this fails. With over 1000 github stars and 76 forks, I doubt the README.md is wrong at this step; I suspect it is something in my local environment.
Can someone help me with the correct steps to make bundle install work?
Use /var/lib/gems/1.8/bin/bundle.
You can also link it to /usr/local/bin, if you want:
ln -s /var/lib/gems/1.8/bin/bundle /usr/local/bin/bundle

Ruby 1.9 - no such file to load 'win32/open3'

I'm running ruby 1.9.2 on Windows and am trying to port code that worked in Ruby 1.8. The code uses Open4.popen4 which previously worked fine. With 1.9.2 I have done the following:
Installed POpen4 via gem install POpen4
Required POpen4 via require 'popen4'
Attempted to use POpen4 like:
Open4.popen4("cmd") {|io_in,io_out,io_er| ... }
When I do, I get the error:
no such file to load -- win32/open3
If I try and install win32-open3 (gem install win32-open3) I get the error:
win32-open3 requires Ruby version < 1.9.0
Does anyone know how I get around this problem?
Haven't used it, but this might work: https://github.com/matschaffer/win32-open3-19
Adding
gem "win32-open3-19", :platforms => :mingw, :git => "github.com/matschaffer/win32-open3-19.git"
to my Gemfile didn't exactly work.
Here are the steps that solved this for me:
Add this to the Gemfile -> gem 'win32-open3-19', :platforms => :mingw
Run bundle to install win32-open3-19
That was it. For me the git location was unncessary and didn't work.

Resources