Best install flow for a new rvm/ruby/pg/rails setup - ruby

I've reformatted my Mac Mountain Lion machine due to lots errors in rails development, broken links, outdated versions, etc, etc. I'm trying to install RVM, Ruby, Postgresl and Rails. I've installed xcode command line tools and I'm looking for recommendations on which order to install the rest to reduce the likelihood that one can't find the other.
Should I install homebrew before any of these? I've read RVM has a new package manager with it that will do most of that stuff, even install homebrew - and not being a unix expert that is appealing. Does anyone have any experience with this?
Also would anyone recommend installing postgres before RVM or after RVM/Ruby/Rails is set up?

Xcode with command line tools
Homebrew
Git
RVM
Ruby
Rails
Postgres
You may at some point get a WARNING form Nokogiri about it being built with one version of LibXML but dynamically loaded with another. You are pretty much stuck with whatever version is being dynamically linked because the MacOS depends on it and it is loaded during boot and Nokogiri needs to be dynamically linked. If you are starting new with Mountain Lion you should be OK. If not, there are dozens of variations of solutions that all amount to compiling Nokogiri against whatever version of LibXML you have in your OS. Hopefully all you need to do if you do run into this problem at some point is
bundle exec gem pristine nokogiri

Related

Ruby, Versions, Gems, Versions and more, Oh My

Apologies for the topic title, couldn't resist.
Basically, For no reason whatsoever apart from trying out different things. I want to implode RVM and try out rbenv. Nothing against RVM, just want to try different peoples software and try different things out.
I can get rid of RVM and install rbenv no problem. Could you guys confirm a few things for me.
Firstly, if I do the above, and then install a few different ruby versions. I know I can place a .ruby-version file in a projects root directory to specify a specific ruby version but then when I say gem install <gemname> I take it that is installed globally for that ruby version.
If I then use bundler per project to manage what gems are used and I specify a gem version, what happens if the version specified in the lock file is different to the currently installed version and what happens if it's vice versa?
I just need a bit of clarification on what's doing what in regards to ruby, versions, gems and their versions.
One of the (many) lovely things about rbenv is that you can so easily look right at your ruby installation to see what's going on. For example, on my machine I can open ~/.rbenv and there's versions containing my ruby installations, such as 1.9.3-p327. Opening that, I can keep drilling down to see my gems installed for that version of ruby (in ~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems). It is then trivial to run gem list or gem install somegem and confirm that what's being affected is this very collection of gems - if this is the current ruby (set in rbenv global and starred in rbenv versions).
In short, everything about your system thinks that ruby means this version of ruby and that its library is this library.
For Bundler, you'll need to install rbenv-bundler. A nice tutorial (easily found with Google) is here: http://dan.carley.co/blog/2012/02/07/rbenv-and-bundler/

Multiple installs of Ruby -- how to solve in OS X

I'm having problems with Ruby scripts finding the right gems. It seems this is related to having multiple installs of Ruby on my system. OS X already comes with Ruby but it's not the latest one. I upgraded from Snow Leopard to Lion and suddenly have all these instances of the rubygems folders:
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems
/Library/Ruby/Gems/1.8/gems/rubygems-update-1.8.11/lib/rubygems
/Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/1.9.2/rubygems
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems
/Users/[user_name]/.rvm/repos/ruby/lib/rubygems
I installed the graph gem with gem install and I can't seem to find it in any of these locations. irb finds it when I do a require but a ruby script saved and run from the CLI produces the error:
'require': no such file to load
Another clue is that when running rails server I often see output from /Library/Ruby/Gems/1.8/gems/
But the graph gem doesn't seem to be in that path either.
So, yes a big mess. Any help to safely simplify this and remove the redundant instances would be greatly appreciated.
Update:
Was able to track the installed gems to:
/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/lib/ruby/user-gems/1.8/gems
So should I just delete everything else with a rm -rf? I'd hate to do that and cause all sorts of dependency problems. Ultimately I'd like to end up with a clean system with only one ruby install but I cannot wipe out my hard drive.
I recommend you use rvm to switch rubies and gems. put a .rvmrc into your project folders and it will switch a "gemset" automatically for you.
The general consensus is to leave the ruby version of the os as it is an use either rvm or rbenv to switch ruby versions.
It does look like you have rvm installed as well as multiple ruby installation installed in different ways too.
Does rvm work correctly, if so you can ignore your other ruby installations.

Which Linux distribution has the most active/recent Ruby support?

I have installed Ubuntu 11.04 and tried to install Ruby as apt-get install ruby. The default version in repositories was 1.8.7, okay, install 1.9.2 manually. Then I'm going for rubygems, download tar file, install rubygems, try to install something with them, zlib-mistake appeared. Found the solution with rvm, didn't help. Now I'm stuck with broken gem command and useless rvm installed.
The question is - which Linux distribution is the most friendly for a Ruby beginner?
The distribution shouldn't matter at all, if you're using RVM (strongly suggested). Otherwise, if you want to have the latest up-to-date packages (including ruby) you could turn to rolling release distros (such as Archlinux or Gentoo). You can always add other repositories to any distro, and get more updated packages this way, as others suggested for Ubuntu.
Update: It's been years since my original reply. Nowadays, with Docker, Podman and toolbx, the distro itself is even less relevant. With containers, one can set up an isolated Ruby environment and ensure developer-production parity.
Why don't you
sudo apt-get install ruby1.9.1
out of the box? Of course, you can also use a community ppa to get 1.9.2 and some common bindings out-of-the-box (so you can work easily with, say, Rails 3.0):
http://www.humbug.in/2010/launchpad-ppa-for-ruby-1-9-2-and-some-ruby-bindings/
Many ruby developers use Ubuntu with rvm. The benefit is that you can install multiple versions and switching them is easy.
Furthermore there are many tutorials and help on errors for rvm.
I would suggest to install a VM and copy it, then and try rvm. If you cripple your system just use the copy again until you setup your system correctly.
Once you know your way around you can install ruby on your system or just stick with the VM like many other do.
On the other hand many server use Debian, wich is slightly different than Ubuntu as it uses older stable packages.

What are the advantages of RVM on linux?

Please understand that I'm not trying to bash RVM. I would just like to understand why it's so popular in the Ruby community.
There appears to be two main reasons to use RVM - to manage/switch between different versions of Ruby, and to manage a specific gemset per project. However there seem to be much cleaner ways of achieving the same thing on linux:
I can install different ruby versions
from the repositories through the
regular package manager, or build
from source and install as a package.
I can switch between versions using
update-alternatives (on Debian, Ubuntu, Fedora at least).
I can use Bundler to manage sets of
gems for different projects, as
outlined in this blog post.
Given the above, I'm confused as to why I would want to use RVM to manage Ruby versions and gems. The idea of using a bash script to install software on my system outside the package manager feels very hackish, a feeling backed up by this blog post.
Not being a Mac user I am totally guessing here, but I thought it might be that OS X is very popular in the Ruby community. If there is no system like update-alternatives for switching ruby versions on OS X, RVM might be the best solution and this idea has carried over to linux too.. like I said, this is just a guess.
So why is RVM so popular, and why should I prefer it over the regular package manager + Bundler on Debian or Ubuntu?
If you need to manage many project with diferent versions of Ruby and special Rails like me (I have 3 project to manage wich uses Rails 2.3.5, Rails 3.0.5 and Rails 3.1 rc1) do RVM is nessesary solution. As you may know Rails 2.3.x has no bundler support and uses old gems so version managing is the way to make developing easier. I hope I helped you alittle.
RVM is portable
update-alternatives works globally, RVM works in shell/script context - I suppose it is modyfying env paths. Now imagine having two apps on one server: one 1.8.7 and another 1.9.2
Usage of Ruby EE requires manual installation - with RVM it is matter of one command to install it.
I had too much problems with mixed gem dirs with 1.8.7 only or 1.9.2 only gems in Debian.
Easy backup - just copy .rvm dir.
Consistent clustering (same platform) - just share one .rvm dir.

Using RVM, how to ensure gems and non-gems see the same version of ruby?

I'm trying to install bdb on Ubuntu as a gem as follows,
gem install bdb
I'm not using sudo, since I am installing with rvm. The ruby version on my system is 1.9.1 but the version I'm using for this installation is 1.8.7 (I'm installing rbot, you see). The problem I've encountered is:
checking for db_version() in -ldb-4.something... no
I assume this means that rubygems is not finding ldb4.something in the places it is looking. Is this because I installed libdb-4.something (7, actually) using sudo, and my system's ruby version is different from the ruby version I'm using for bdb? Using rvm, how should I manage this sort of situation? Maybe I'm doing things wrong, but it seems to me that my problem is that not everything I'm using is a gem, and the stuff that isn't gems is seeing the wrong version of ruby.
(if it turns out that my problem is something completely unrelated: I am still interested in the question. How do things I've installed on my system with a particular version of ruby get along with gems installed using rvm under different versions of ruby?)
"How do things I've installed on my system with a particular version of ruby get along with gems installed using RVM under different versions of ruby?"
They don't, and that is the point. RVM is for managing different versions of Ruby so that they are isolated from each other.
This means that the Ruby versions that you use for system (when you do sudo gem install that would be installing to system) have nothing to do with the current environment (when properly set up.)
When you are in a RVM environment, each version of Ruby installed is an isolated environment.
What I would recommend is this:
Go to the RVM Website and check it out.
At the end of the page, continue with your reading about how to use gemsets.
go to your project directory
rvm use 1.8.7#your_project_environment
create your .rvrmc file so that you will automatically be using this environment in your project on the future visits to this project, this file can contain "rvm use 1.8.7#your_project_environment" which will achieve this.
install all required gems
If you have additional questions, feel free to visit Wayne E. Seguin and a ton of other users of RVM and we will be happy to help you out. Of course, the first search for answers is the documentation on the web site.

Resources