Upgrading Ruby on Mac OS X - ruby

I am reading the book Programming Ruby and am looking to upgrade the version of Ruby on my computer. I run Mac OS X Snow Leopard and doing ruby -v in the command line shows I am running Ruby 1.8.7.
I installed MacPorts and ran the sudo port install ruby19 command but whenever I type ruby -v, it still shows Ruby 1.8.7.
Could anyone help with this? Thank you.

The tool "rvm" is pretty good. It stands for Ruby Verson Manager I think, and the developer is good at support in the irc channels. You can install multiple versions of ruby along side each other pick the ones you want to use.
http://rvm.io

You have to use ruby19 to run ruby if you installed it that way. You can also use irb19, and ri19.

I updated the link to RVM in one of the answers, but also a quick poll of some friends doing Ruby dev currently revealed a preference for rbenv as a ruby environment manager: http://github.com/sstephenson/rbenv/

As mentioned in hvgotcodes answer, RVM seems to be a great way of handling this.
I recently started learning Ruby (and Rails) myself, and this[1] tutorial has a great section on using RVM. I'd highly recommend you give it a go, it's especially handy so that you can follow different tutorials on different versions of Ruby if you wish.
[1] http://railstutorial.org/book#sec:rubygems

As #Andrew Grimm eluded, the problem you are having is likely due to a problem in your $PATH variable. Since macports typically installs stuff in /opt, modifying your $PATH variable to:
$ export PATH=/opt/local/bin:$PATH
Will most likely help. However, I would urge you to look into RVM as #hvgotcodes recommends.

Related

How can I install Ruby to be used as a notebook in the Jupyter Web UI (Mac OS 10.10.5)?

I've found several pages that purport to tell me how to do this but I've had no success so far.
FYI, I've never used Ruby or any part of its ecosystem (Gem? That's clever!) so I'm swimming in a sea of new terminology and assumptions.
I have Jupyter 4.1.0 installed. When I boot it with jupyter notebook I get the web UI and under the "New" menu and under "Notebooks" I only see Python 2. I would really like to see "Ruby" like I do on the Try Jupyter page.
I tried following the instructions on this page:
https://github.com/SciRuby/iruby/tree/master
It seemed to suggest that for an installation involving Python 2 I should use the installation instructions found on the IPython2 branch. I t actually seemed to suggest that I should do that if I had IPython2. It seems I actually have IPython 4.1.2 but the first instruction set didn't work so. Furthermore, I don't actually understand how IPython factors into all of this as I started using Jupyter when it was already called Jupyter.
When I tried to follow the master branch instructions Gem told me
iruby requires Ruby version >= 2.1.0
Apparently I have ruby version 2.0.0p481.
Then I wasn't sure how to upgrade ruby. Gem? Brew? Pip? Binary?
I was, eventually, able to install iruby version 1.9 with Gem but it didn't show up in the Jupyter UI. I restarted the Jupyter server, closed the terminal and started it again, etc with no success.
I'm going around in circles here and I'm sure it's slightly less complicated than it seems.
Is there a config file somewhere that tells Jupyter which kernels to
load?
Is there a PATH variable that needs to contain the iruby binary?
Also, unless this statement alludes to a serious misunderstanding somewhere, I'm not (yet) interested in Ruby on Rails. I'm under the impression that is some sort of framework that I may have use for some day. For now, I just want a little playground for ruby. (I know there are online ruby IDEs out there but I really like Jupyter and it seems like I can do it there. So I wanna!!)
Here is a summary of a few of my details so far.
Mac OS 10.10.5
Python 2.7.11
Gem 2.0.14
IPython 4.1.2
Jupyter 4.1.0
I have plenty of experience with Python.
I have zero experience with Ruby.
Thank you, in advance, for your help!
You need to upgrade RUBY version. By default OS X comes with ruby 2.0 which is really old as per current standards
For Mac the best way is
brew install ruby
which will install the latest version of ruby
Once that is done just install iruby gem
sudo gem install iruby

Specify ruby version to use with Pik

I need to run two Ruby apps on a Windows 2008 server. So, I'm thinking to install Pik for the job (I understand I could use also RVM but the install process doesn't seem very 'stable' to me).
Before installing Pik, however, I'd like to know if there is a way to specify which Ruby version should be used for each app. Something like a .ruby-version file. I have looked for the answer on the official Pik repo but I couldn't find anything about it.
In my opinion, Ref 1, Ref 2 are the two simple references you could have to install different ruby versions using Pik in Windows.
After setting up the environment correctly, you could just use the command similar to RVM.
pik use ruby-2.0.0-p0
Then ruby -v will show ruby 2.0.0p0. So, for different projects, from with in each project folder choose which ruby you want to have.
Hope it helps :)

Why doesn't rails.vim recognize any gems that I install?

I'm a ruby and vim newbie. I recently installed the rails.vim plugin and all the commands work fine apart from the commands to create a new Rails project. Every time I do this it says rails is not installed on my system, but it is! It also acts up when I create a class that requires a gem that I've installed. Can anyone help with this?
Did you rvm use system before building / brew install-ing macvim? I didn't and got many errors. Doing rvm use system beforehand fixed things up for me.

RVM causing path issues with installed gems on Ruby 1.9.2 - unable to annotate, etc, do I need to reinstall RVM?

I'm on Mac OSX Snow Leopard. I tried to post a similar question to the RVM Google group but it did not seem to get posted.
I'm worried that I've done something fundamentally wrong with my RVM install that's causing these errors, that seems to be related to paths, at each step of the way. Have any of you seen this behavior before?
I started to teach myself Rails programming as of about two months ago with a working environment of Ruby 1.9.1 and Rails 3.0.3, based on a hivelogic install tutorial that had me modify my ~/.profile file and install the relevant bits to ~/usr/local/src/. For reference, the line in my ~/.profile file was this when I installed RVM, if that makes any difference:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/src:$PATH"
In my terminal I installed RVM as a user using the standard user github bash script.
I tried to install Ruby 1.9.2, which kept running into a weird error about a libfile somewhere. After much Googling I found someone on Stack Overflow that recommended renaming the ~/usr/local directory while performing the Ruby install -- I did this, and the install complete.
Then I did gem install rails and tried to do bundle install in my app, which gave an error when trying to install the SQLite3 gem (even though I already had SQLite3 installed and working). Again, I spent a day Googling this and eventually found "Unable to install sqlite3-ruby gem" that said if I used Macports to sudo port install sqlite3 it would work.
I tried that from the base directory, and Macports did its thing but it didn't fix the problem. Then I did the same thing from my app directory and it fixed the SQLite3 error I was getting.
Now I am able to run rails server and rails generate again, which is great, but then I tried to "annotate" my new model, and I get this error: http://pastie.org/1481570
I have not yet solved this issue, and have looked at many threads of similar issues. This, for example, did not solve my problem: https://github.com/james2m/annotate_models/commit/5997da9692c9b222e8d1be22dfad6ed8638c16a1
I even tried copying my source code directly into the rvm/user/ directory in case that relative path was causing problems, but it doesn't seem to have fixed anything. Maybe I need to uninstall RVM and re-install it as root instead of a user-level thing?
What do you think is the best way to get annotate to work and hopefully get RVM to play nice with my gems going forward?
I'm unfortunately REALLY new to terminal, code, etc, so any help would be much appreciated.
On Snow Leopard you should modify either ~/.bashrc or ~/.bash_profile, preferably the later. Also, RVM will not need anything in ~/usr/local since it's entirely self-contained in ~/.rvm.
RVM uses a nice little shell function to sense the needed directories and desired default Ruby. I suspect either the instructions you followed were very out of date, or poor recommendations. The current RVM installation requests you add:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
to your ~/.bash_profile
The RVM site has lots of troubleshooting tips for things like MySQL. I'd strongly recommend backing out of the things those other tutorials had you do, and refer to the instructions on RVM's site. It is very easy to get things working right if you do it the RVM-way.
Download and install Apple's latest version of XCode from their Developer site if you haven't already. There have been some broken versions shipped on the DVDs.
Install. In particular follow the "Post Installation" section.
Following that, do whatever rvm notes says to do as far as libraries. Following that, you should be able to use rvm info to gather useful info about your installation. It is your best friend.
Database integration will point you to how to fix MySQL's wagon.
RVM development happens fast. Keep it updated, at least once a week using rvm get head.
At that point you should be in a good place to start reinstalling gems.

Installing Ruby on Mac 1.9.2, still getting 1.8.7 even though path changed

I'm on a Mac running 10.6.4 Snow Leopard, and apparently ruby comes ready to go. But I'm new to Ruby, trying to learn the Rails framework, and so i decided to install the latest version 1.9.2. I followed the instructions here, but after I compile and install, when I run ruby -v I'm still getting 1.8.7. Anyone can help a noob out?
When I use which ruby I am getting usr/local/bin/ruby, so the path has changed and is correct.
UPDATE:
It seems I was having issues because I was using two login files to set my path (.bash_login and .profile). You can only use one, and the first one that exists and is readable will be used. I eventually switched to RVM and used .bash_login to load RVM into shell.
Well, the sw isn't lying to you. So something is not as you expect.
Try /usr/local/bin/ruby -v and see what version it is.
Added: Also, try locate ruby|more to see where the ruby files are on your system.
You may need to change your path to use your newly installed copy of ruby.
Added more: did you add the Path to your ~/.profile file as the instructions tell you to do in step 1?
Did you restart your terminal session after changing the ~/.profile file? (Quit and restart terminal.)

Resources