RVM & GDAL - Linking external libraries - ruby-on-rails-3

I am using GDAL in my rails 3 project. I cannot seem to figure out how to get it to work properly without defaulting to the system ruby. Rails complains that it can't find "gdal/org" even though its installed. How can I make this link in RVM and still use my ruby gemset?

Sounds like you installed the libraries but how are you trying to have Ruby utilize them? Per my understanding, installing libgdal-ruby via apt would install everything in the system paths which wouldn't be automatically loaded by default by a Ruby installed via RVM nor your Rails application using Bundler, which isolates gems. Perhaps you can try setting something like
ENV['LD_LIBRARY_PATH'] = "#{ENV['LD_LIBRARY_PATH']}:/path/to/gdal/libs"
in your environment.rb to include the libraries for gdal. You might also need a custom initializer to require it on application boot.

Better yet I found this gem which works perfectly: github.com/zhm/gdal-ruby.

Related

Railsinstaller with ruby 1.8.7

Can anyone tell me how to install rails in windows7 with ruby 1.8.7.
I recommend installing a ruby version manager such as pik to manage installing a sandboxed 1.8.7 - in particular, look at the readme on the github page for using a msi installer package to install ruby from scratch. A ruby version manager is incredibly handy to have, as it lets you flip back and forth between different rubies, with different installed gems, and, if this is important to you, can install various rubies without requiring admin privileges (to run the installer package for pik may require admin privileges).
From this point, use the standard Ruby tools like gem to install Rails. I recommend installing bundler with gem install bundler, then using bundler to handle the rest of your gem needs, as is detailed in the bundler link and especially here. Bundler is great because it manages your configuration precisely based on a file in the directory; this means multiple projects can have multiple versions of different libraries installed, but Bundler makes sure that the configuration is consitent for each project. You can even move your project (including your bundler Gemfile) to a different computer and run bundle install and it will ensure your other computer is using the exact same versions of the same gems for running your software - great for deployment.

System ruby/gem vs RVM ruby/gem

I installed RVM, read the documentation and do not understand it well. For example, I had an rails application that is created and run just find (before I install RVM) and it uses the system ruby and system gem. Now after I install RVM:
Do I need to re-install these gems into RVM so these gem can be under RVM control?
How to a port the application to use RVM gem instead of system gem?
Is RVM a wrapper for ruby and gem or a separate repository of these ruby and gem? So if I install a gem under RVM, the gem only exist in RVM or exist across RVM and system, or vice versa. Am I duplicating or does RVM and System synchronize their gem/system themselves?
I am still completely confused of the goods and uses of RVM. Now all my previous applications that used to work not doesn't even start with various errors.
My environment: Mac OS X 10.8; Rails 3.2.9; TextMate
Yes. Use bundler and there will be no pain.
It just need to be run in RVM environment. No special porting required.
It is intended to provide separate environment for each of your projects by substituting environment variables like $PATH, $GEM_HOME, $GEM_PATH.
Pros:
You can have different ruby interpreters installed to fulfil your applications' requirements. Imagine that you are starting a new project with Rails 1.9.3, but you are still working on old two which use 1.8.7 and 1.9.1 and have not been ported so far.
Your gems does not conflict with each other. For example Psych has special needs. If you use it, you got to use it in all your project. But with RVM you can create different gemsets for each project.
Moves gem directories too dirs where you got read+write access. This is good because does not force you to compile gems with root privileges.
Cons:
I had problems with RVM when using it for long time under Fish shell. Two times, after some weeks whole RVM went crazy and just get broken. Not going into details, I got to remove whole ~/.rvm directory. Never happened under Bash.
My typical workflow with RVM is following:
Add ruby "1.9.3" or equivalent to Gemfiles of my projects to avoid running it with wrong Ruby version.
Install RVM and install Rubies I need, rvm install 1.9.3.
In given project, rvm use 1.9.3.
Install required gems.
Use my app normally.
Please note I am not using Gemsets. This is because of Cons #1. I really love Fish shell, can't live without it, and bundler alone gives me decent management of Gems (one problem: Psych). To use Gemsets, two additional steps between 3. and 4.:
3a. Create one rvm gemset create gemset1.
3b. Use it rvm use gemset1#1.9.3.
I always use RVM when working with some legacy projects.
Refer to this screencast: http://railscasts.com/episodes/200-rails-3-beta-and-rvm for decent tutorial.

How can I make rbenv install certain gems automatically?

I always want bundler and gem-ctags to be installed in any Ruby I have installed. Is there a way to make rbenv / ruby-build install them automatically?
RVM has #global gemsets; is there an equivalent in rbenv?
Use rbenv Plugins
By default, rbenv doesn't use gemsets. People who love rbenv probably just hack their GEM_PATH and GEM_HOME when they want different gems, but there are also some plugins that automate some of this behavior. Two that I know of are:
rbenv-vars by Sam Stephenson (the author of rbenv)
rbenv-gemset by Jamis Buck
Use Bundler's --path Flag
Of course, you can also just use bundler with a --path flag to install bundled gems to a unique directory instead of using gemsets. The bundle-install(1) docs say:
--path=<path>
The location to install the gems in the bundle to. This defaults to the gem home,
which is the location that gem install installs gems to. This means that, by
default, gems installed without a --path setting will show up in gem list. This
setting is a remembered option.
Consider the "Batteries-Included" RVM Instead
The argument for rbenv is that is simpler and does less under the hood than RVM. I'd argue that if you need to add ruby-build, rbenv-gemset, and other plugins to get the functionality you need, then you may as well use RVM in the first place.
This isn't a critique of rbenv, or praise for RVM. I'm just pointing out that if you want a tool that gives you most of RVM's functionality, you might was well just use the tool that gives you want you want "out of the box" rather than bolt the functionality on post facto.
You can certainly do what you need to do with rbenv, one way or another. I'd just suggest that you not put yourself in a position where you have to fight your tools to get things done.
I wrote a little shell script that tells Gem to add particular gems to any Ruby currently set. That way it works whether I'm using rbenv, RVM or I'm on a machine where I installed Ruby from source by hand.

Can I "move" my gems while upgrading Ruby 1.8.7->1.9.3 and Rails 3.0->3.2?

I am Ruby/Rails beginner, and I am on Windows.
I just used RailsInstaller to upgrade from Rails 3.0.9 to 3.2.3, from Ruby 1.8.7 to 1.9.3. The gems that I installed previously no longer appear when I type gem list. I assume this is normal.
My question is: Is there a way to get all of those gems "into" Ruby 1.9.3 without individually re-installing them?
When I went into an old rails apps and ran bundle install, it appears that a few of my gems were re-installed (the ones in the Gemfile).
Any help would be appreciated. Sorry if I am missing something obvious.
If you're just upgrading to a new version, as long as everything that was in your Gemfile was installed when you ran bundle install then I wouldn't worry about it. Just re-install gems as you need them instead of bloating your system with gems that you don't currently need.
If you have projects that you are porting over to the newer versions of Rails and Ruby, you can just run bundle install as the first step in upgrading the app to make sure its dependencies are installed.
Maybe someone could give you an yes/no answer for transitioning with RailsInstaller, but I'm trending toward using rvm and gemsets to have a cleaner, more focused environment for each project.
If you want to switch back and forth between multiple ruby versions, maybe check out the gem pik. You can use it to install gems on multiple versions of ruby so that they're available across them all.

Issues with Rails3.0 vs Rails 3.1

So I finally upgraded (and then downgraded because of Unity) Ubuntu and reinstalled RVM but I'b stuck with rails 3.1 now, which is fine but all my old projects are in rails 3.0 and 3.1 has some incompatibilities. Off the top of my head RAILS_ROOT is now Rails.root (which all my projects use in someway), and I was having some issues with heroku when trying to upload a small rails 3.1 app I made to play around (since the PG gem wasnt in my gemlist I couldnt run migrations, and then installing the pg gem caused more issues).
So how do I install rails 3.0 again? I cant seem to find it in the repositories
And I know with gem sets I can install both right? Well if I do that, how do I create a new rails project? Which version of rails would use rails new new_app?
Ok, I understand what you need to do. I would highly recommend making a new Gemset using RVM, that way you can start from scratch and not worry about those things.
To do that, run this in your command line with RVM installed:
// EDIT THIS LINE TO MATCH WHAT YOU WANT
rvm use 1.9.2-or-which-ever-version-you-are-using#temporary_gemset --create
Once this gemset is created, it will be empty, so you can then proceed to install a younger version of rails, like so:
gem install rails -v 3.0.11 // (MAY NEED TO USE SUDO, DEPENDING ON YOUR SET UP)
This should install the older version of rails and its dependencies so that you can still edit and work with your older rails project. Check more of RVM's site for more help on switching between gemsets and creating them.
https://rvm.io//gemsets/
I would still recommend to figure out the differences eventually and move to the newer version for Rails, currently 3.2.5 because they are awesome. Here is some material to show you the differences and new features for when you do that later:
http://railscasts.com/episodes/265-rails-3-1-overview
http://railscasts.com/episodes/282-upgrading-to-rails-3-1
http://railscasts.com/episodes/318-upgrading-to-rails-3-2