Ruby on Mac OSX via Mac Ports - ruby

I'm new to both Ruby and to Mac OSX, though I do have a fair amount of experience with Unix commands. I just installed Ruby 1.9 via a MacPorts command (port install ruby19). I then needed to do a find from root just to figure out where it went, which turned out to be: /opt/local/var/macports/software/ruby19/1.9.1-p376_0/opt/local/bin/ruby1.9.
The current version of Ruby (1.8.6) runs via /usr/bin/ruby, which is a symbolic link to /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby where Current is a symbolic link to a directory called 1.8.
I'd like to make Ruby 1.9 my default (along with related tools like irb), and while I can manage to do that, I'd like to know if there's a conventional way. Should I copy or link the MacPorts path to /System/Library/Frameworks/Ruby.framework/Versions/1.9 and then point Current to 1.9? (I'd also have rename or copy the executables: ruby1.9 to ruby, irb1.9 to irb, etc.) Or should I just blow away the /usr/bin/ruby link (and /usr/bin/irb, etc) and create new ones pointing to the MacPorts version?

You can easy to use port select command, under MacPorts 2.1.3
$sudo port select --set ruby ruby19

Install the nosuffix variant instead:
sudo port install ruby19 +nosuffix
Your newer ruby version should now take precedence over the preinstalled one.

My advice:
$ port uninstall ruby1.9
Then follow this: https://rvm.io/rvm/install/
Then:
$ rvm install 1.9.2
$ rvm --default 1.9.2
You might even rvm install macruby to toy with Cocoa.

In the lastest version of macports (2.1.3 or greater) you can use the port select command.
port select --list ruby
sudo port select --set ruby ruby19
For earlier versions of macports you can make a symbolic link to the numbered ruby version. This is the way that macports generally handles switching between different versions of packages.
cd /opt/local/bin
sudo ln -s ruby1.9 ruby

I would highly recommend RVM. It takes a bit of reading, but once you have it installed you can install a ruby with rvm install 1.9 (or jruby, ree, 1.8, etc), and switch between them with rvm 1.9. Each ruby version will also have its own, completely isolated set of rubygems.

The ruby1.9 binary should be installed in /opt/local/bin; if it's not, you may not have activated the port.
The easiest way to make Ruby 1.9 the default root is to create an alias for ruby to ruby1.9. If you're using Bash, you can do that by putting this in your Bash config file:
alias ruby='/opt/local/bin/ruby1.9'

Uninstall ruby version 1.8:
sudo port uninstall ruby
Install ruby version 1.9:
sudo port install ruby19
Reopen terminal

Related

How to install Ruby 1.9.2-p290 via macports

I am trying to install Ruby 1.9.2-p290 via macports. I just installed the port 'ruby', and I ended up with ruby 1.8.7. Any idea how to install a specific version of ruby?
I've heard the use of rvm, however, I dont seem to have rvm on my mac. Would it be better than macports? If yes, why and how can I get it? Would it be possible to get it via macports?
Thanks!
rvm may be an excellent answer if you're going to be working with ruby a lot, but that's not the actual answer for why MacPorts appears not to do the correct thing.
By default, the MacPorts ruby package installs the binary as /opt/local/bin/ruby19. If you run which ruby19 that should confirm it was indeed installed by MacPorts correctly.
This is not what anybody expects though, so it helps to know the poorly documented select command syntax. As of MacPorts v2.1.3, the proper way to make the MacPorts-installed ruby19 the "system default ruby" is: sudo port select --set ruby ruby19
In older versions the "proper" way to make ruby19 the default was to install the +nosuffix variant (which no longer exists) like this: sudo port install ruby +nosuffix.
If I remember correctly, ruby 1.8.7 is the stock ruby on OS X. If you install another Ruby version (with MacPorts for example) you will have to tell your OS to use it instead of the stock one. It can be very messy this way.
So I recommend hardly to use rvm. It will be better than Macports, because you will be able to install the Ruby version you want. You can even have multiple Ruby version and switch whenever you want.
Rvm is not installed by default on your Mac, but consider checking out this simple guide to get started.

why my ruby version is still an old version on ubuntu after I installed ruby1.9.2?

I am newbie to ubuntu and ROR. After installed latest ruby1.9.2 with apt-get, type "ruby -v" it still shows up old version ruby1.8.7. I tried to reinstall with rvm, nothing changed.
As mentioned in similar question, I tried to remove ruby, and reinstall ruby1.9.1-full... still the same thing...
What else I can do about this?
ubuntu uses a something called alternatives for chosing between two version of similar executable. Running
sudo update-alternatives --config ruby
and chosing the ruby you want should do the trick
I'm using RVM myself, but if I remember correctly, ruby1.8 and ruby1.9 can be installed side by side on Ubuntu. ruby is just a symbolic link which points to version 1.8 by default - which should be called ruby1.8 and stored in the same directory. 1.9 will be called ruby1.9.
So just find where ruby symbolic link is (whereis ruby) and change it so it points to ruby1.9.
sudo rm /path/ruby
sudo ln -s /path/ruby1.9 /path/ruby
Sounds like you are using rvm, but still referencing system ruby. To switch, you have to tell rvm what version to use.
rvm use 1.9.2
This will switch your current environment only. So ruby -v in your current shell will use the right version. (you should probably go with 1.9.3, FWIW) If you want to always use that ruby be default, you type:
rvm use 1.9.2 --default
If you want to switch back to system ruby, you can use:
rvm use system
I think it is because the package of Ruby version at apt-get repository is an old version.
I suggest use rbenv to install the latest version.
Here is a great tutorial using rbenv to install the latest Ruby version from Digital Ocean:
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04
sudo apt-get install ruby1.9
should do the trick.
You can find what libraries are available to install by
apt-cache search <your search term>
So I just did apt-cache search ruby | grep 9 to find it.
You'll probably need to invoke the new Ruby as ruby1.9, because Ubuntu will probably default to 1.8 if you just type ruby.

Ruby 1.8.7 to 1.9.1 on OS X 10.6

I am currently learning Ruby using Ruby 1.8.7 (pre-installed on OS X 10.6) but understand the latest version is 1.9.1?
Is it a requirement for me to 'upgrade' this to get the most out of the language? What are the differences between 1.8.7 and 1.9.1?
If an upgrade is advisable can anyone advise how I should go about upgrading my Ruby?
Currently the stable release is 1.9.2.
It's not mandatory to upgrade, although 1.9.2 offers better performance and some nifty features (e.g.: better Unicode support, Time and regex improvements, etc.).
Choosing to upgrade mostly depends on what you need to achieve, but I would suggest to install Ruby Version Manager, so that you can install all the versions you want and easily switch between them.
You can find all the info at https://rvm.io and a nice guide here: http://ruby.about.com/od/rubyversionmanager/ss/Installing-Ruby-On-Snow-Leopard-With-Rvm.htm
There is nothing like a requirement but it is strongly encouraged by the community
to use ruby 1.9.2.
The best way to give it a try is through RVM
RVM is cool. But probably later you will need another gnu software, not native in OS X. Therefore, i'm recommending to use macports.
go to www.macports.org
download the installation dmg
install it
open an new Terminal windows (or source ~/.profile )
Enter the following
sudo port selfupdate
sudo port install ruby19
port search rb19-
pick what you want and install them with port install command. (as above), for example
sudo port install rb19-rails
sudo port install rb19-rails_best_practices
sudo port install rb19-actionpack
and so on...
Note
everything will compile, so need Installed Apple Developer, and will take a long time.
you need to use /opt/local/bin/ruby and not /usr/bin/ruby
Everything will go into /opt/local tree - so does not interfere with your standard system binaries - your system remain untouched.

How to update system Ruby to 1.9.2 on Mac?

I saw an answer saying I should use RVM. But I don't know how even after:
$ rvm system
$ rvm current
system
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
The title of the question, "How to update system Ruby to 1.9.2 on Mac" makes me wonder if you are trying to upgrade Apple's installation of Ruby 1.8.7 to 1.9.2. If that is true, STOP and do NOT try that. The Ruby installed by Apple is for their use, and apps installed by Apple use it.
find /usr -name '*.rb'
will list the reasons why.
RVM and other apps allow you to install Ruby safely, so unless you have very good knowledge of how Unix and the Mac work I strongly recommend you stick to them.
A very common problem we see is that the installation wasn't completed. Read the "Installation" section in the RVM installation page to double-check you've completed everything.
To install Ruby 1.9.2 do:
rvm notes
and read and install the needed dependencies. Then do:
rvm install 1.9.2
rvm use 1.9.2 --default
will tell RVM to always use 1.9.2 as a default. You can switch to the system version installed by Apple using:
rvm use system
and switch back using
rvm default
If you don't want an RVM-based solution:
Download and install Apple's Xcode developer tools so you get GCC et al, the ability to build your own software. (This is 4.25GB, but you only need to download it once.)
Download and extract the Ruby Source Code. (10.6MB)
Open a Terminal window and change into the directory of the source code.
Run the command ./configure && make; get a cup of tea while you wait
Run the command sudo make install to install this Ruby; you'll need to supply your administrator password
Modify your PATH environment variable to put /usr/local/bin in front of /usr/bin (so that your new Ruby is found before the system Ruby). You can do this by creating or editing a .profile file in your home directory to have the line:
export PATH="/usr/local/bin::$PATH"
If you're running TextMate, you'll also want to go to TextMate ▸ Preferences ▸ Advanced ▸ Shell Variables
and add or edit a PATH variable like this:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
After this, rvm use system will use your 1.9.2p180 (the current version as of this post) install.
I'm assuming you're not sure how to install a new version of ruby with RVM - try:
rvm install 1.9.2
To then make it the default version to use:
rvm use 1.9.2 --default
Consider also: "for OS X try using RailsInstaller for OS X or try the official RVM GUI JewelryBox" -- Quoted from from the 4rd or 5th screen the RVM install page found here http://rvm.io/rvm/install
Whatever you do do not touch or mess with the system default Ruby that ships with your Mac I did that to see what would and my system was out of whack. If you would like to use a different version of Ruby use rvm.

making ruby 1.9 default on os x [duplicate]

This question already has answers here:
Installing RVM (Ruby Version Manager)
(2 answers)
Closed 8 years ago.
How do I make ruby 1.9 the default version to use instead of the 1.8.x that is by default installed on os x?
Thanks.
As of v2.1.3, the "correct" MacPorts way of setting a specific version of a package as the default is to use the select command, like this:
sudo port select --set ruby ruby19
There doesn't appear to be any documentation about this command in the MacPorts Guide. You can however run port help select to get a very limited description. This functionality replaces the +nosuffix "variant" style of setting the default version.
I recommend installing the RVM tool from http://rvm.beginrescueend.com/ (it has instructions on installing it
It allows you to have multiple versions of ruby and gems. After installing RVM, then install the Ruby 1.9 you want, using:
rvm install ruby-1.9.1
To make it the default one:
rvm --default ruby-1.9.1
After this, it will be the default ruby.
RVM is great for setting up multiple environments with different versions of Ruby and gems.
If you however just want to have Ruby 1.9 you can simply install it using MacPort. It will take precedence over the one already installed by default on OS X.
Download MacPort if you haven't already. It's the Mac package manager.
On a Terminal, use MacPort to install Ruby 1.9 and RubyGems
sudo port selfupdate
sudo port install ruby19
sudo port install rb-rubygems
You should then have Ruby 1.9 installed and ahead on the path. Do a ruby -v to check. Use Ruby gems to install any other Ruby components like Rails.
Ports are installed in the /opt/local/bin directory and MacPort updates the PATH environment variable so that these are picked up before the /usr/bin pre-installed packages.
you could create an alias rather than a symlink...this way both versions are left intact. add the following line to .profile in user's home folder (create if doesn't exist):
alias ruby='/opt/local/bin/ruby1.9'
then source the file:
source .profile
hope that helps :)
I would say skip the rvm.
In my case, MacPorts did prepend /opt/local/bin to my path, but installed ruby 1.9 as ruby1.9. (Leaving ruby -> /usr/bin/ruby.)
By far the easiest way to fix:
sudo su
cd /opt/local/bin
ln -s ruby1.9 ruby
Poof. Done.
Exact commands:
nsmcs-macbook-pro:~ nsmc$ which ruby
/usr/bin/ruby
nsmcs-macbook-pro:~ nsmc$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
nsmcs-macbook-pro:~ nsmc$ which ruby1.9
/opt/local/bin/ruby1.9
nsmcs-macbook-pro:~ nsmc$ sudo su
Password:
sh-3.2# cd /opt/local/bin/
sh-3.2# ls -l ruby*
-rwxr-xr-x 2 root admin 9040 Feb 16 07:43 ruby1.9
sh-3.2# ln -s ruby1.9 ruby
sh-3.2# which ruby
/opt/local/bin/ruby
sh-3.2# ruby --version
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10]

Resources