two versions of ruby installed, how to fix that? - ruby

I found out that I have two versions of ruby installed on OSX 10.6.2 how can I uninstall the older version and make sure that everything is fine, the path point to the other one?
bash-3.2$ /usr/local/bin/ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.7.0]
bash-3.2$ /usr/bin/ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
bash-3.2$ $PATH
bash: /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec: No such file or directory
bash-3.2$ whereis ruby
/usr/bin/ruby

The version of Ruby in /usr/bin is the system-installed version, and should be left in place.
The version you have in /usr/local/bin can probably be safely removed. Was it installed using a package manager (ie, MacPorts, Homebrew?). If so, remove it using your package manager.
If you compiled and installed it manually, you can try removing the binaries from /usr/local/bin, but you may still have gems and other files lying around (most likely in /usr/local/lib/ruby.)
Alternatively, you can leave them in place and manage your Ruby environment through RVM: http://rvm.beginrescueend.com/

You should locate the Ruby you're actively using with which ruby, not whereis ruby. My whereis ruby outputs /usr/bin/ruby, but which ruby gives /Users/BinaryMuse/.rvm/rubies/ruby-1.9.2-p136/bin/ruby, because I manage my Ruby versions with RVM. Since /usr/local/bin is first in your PATH, which ruby will probably return /usr/local/bin/ruby, which appears to be what you want. A quick ruby -v can confirm this too.
All that being said, I second the recommendation of using RVM to manage version of Ruby and also what RVM calls gemsets, allowing you to have "buckets" of gems that you can use one at a time. It's quite a powerful and extremely useful tool.

You don't have to uninstall the the older version. ALternatively you can use alias like and save it in the ~/.profile file of your the OSX directory.
alias ruby="<path_to_ruby_version_that_you_want_to_use>"
That should call ruby from the proper directory that you want.
Alternatively you can use symlink like this post suggests here How to uninstall Ruby from /usr/local?. Hope it helps!

Related

How to correctly update system ruby version to latest version (2.2.1) on OSX

Just trying to update to the latest version of Ruby. On ruby-lang.org/en/documentation/installation/#homebrew, I found that you should be able to do it via homebrew:
brew install ruby
However, when I listed the ruby version (ruby -v) after it 'updated' it was still at the old version 2.0.0.
Hermes:~ Sancho$ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin13]
I happened to list the contents of /usr/local/bin/ and I could see a symbolic link:
ruby -> ../Cellar/ruby/2.2.1/bin/ruby
So, I don't know what's happening and why the version still lists the old number and not 2.2.1, as it looks like it should.
There are sym links to for various other ruby tools (erb, gem, irb, rake, rdoc, ri) to version 2.2.1 also.
So what is happening here and how do I correctly install version 2.2.1?
I do have RVM installed also, but I want to update the system version of ruby to the latest.
Easy step
brew uninstall ruby # (if installed)
brew install ruby
then copy the path and paste into the terminal and restart the terminal
check ruby --version
Use Homebrew but make sure /usr/local/bin is early in your path. Ex:
.bashrc
export PATH=/usr/local/bin:$PATH
This will not update the system Ruby version. Instead it will install another version of ruby and this line tells bash to look for the new version instead.
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
$PATH doesn't change in current Terminal session. So please close the Terminal and reopen.
Ref: Jekyll on macOS

What is the point of installing the same version of Ruby through RVM as the system Ruby?

I've been using the default system ruby version 1.8.7 without RVM for a few rails projects and have not run into any problems. I just recently installed RVM, and after running rvm requirements I get this output:
To use an RVM installed Ruby as default, instead of the system ruby:
rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7
I believe what these commands do are to install the same gems that have already been installed using the system ruby under the RVM installed ruby.
My questions are, am I right in what these commands do? and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The one thing that springs to mind is, if you use the system Ruby, you'll use it slightly differently that RVM's Rubies--for example, you'll likely need to use sudo to install gems. Furthermore, you won't be able to use many of RVM's features, like gemsets, with the system Ruby.
Well one reason I can think of is that you don't wanna worry about your system not working even if the system ruby gets updated.
My questions are, am I right in what these commands do?
You are right in what they do. The first command installs Ruby 1.8.7, the second command installs all the gems currently install on your system Ruby installation in the new RVM Ruby 1.8.7 installation, and the third command sets your default version of Ruby to be the RVM Ruby 1.8.7.
and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The second command is actually more of about convenience than necessity. Yes, the gems install in the RVM 1.8.7 will be completely separate from the ones installed in the system version of Ruby; however, if you didn't run the second command, you're RVM 1.8.7 would start out with almost no gems (only the defaults). That means that you would need to go through and manually install the gems that you need to get your project up and running. Instead of doing that, the second command allows you to just install the same gems you've already installed in the system version of Ruby to the RVM 1.8.7 version—it doesn't migrate them, it just makes a copy of them. After the second command, there are two distinct sets of the exact same gems: one in the system Ruby and one in the RVM 1.8.7 Ruby. So, if you were to update gems in either of the Rubies, they would get updated, but the other version's gems would be unaffected.
Hope this helps answer your question.

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.

how to change ruby path from /usr/bin/ruby to /usr/local/bin/ruby

reading around the various ruby install tutorials it's required to change path from /usr/bin/ruby to /usr/local/bin/ruby but i cant seem to be able to do it. Ultimately i want to install Ruby 1.9.2, should i uninstall 1.8.7 or what? i tried to install Ruby 1.9.2 with macports, the installation seemed to go ok, but i cant find the new version, i seem to be stuck with 1.8.7
iMac:~ rebel$ which ruby
/usr/bin/ruby
rebel$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
.profile
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
From your shell I notice you are on a Mac. If that's true, I recommend you to have a look to Homebrew. Then follow the instructions and install RVM for Ruby. With RVM you don't need to uninstall ruby, you can have several versions encapsulated in their own directory. You simply switch from one version to another according to your needs.
For example you can have ruby 1.9.2 with rails 3.0.1 in one setup and in another one you can have ruby 1.8.7 with rails 2.3.8...
In Mac, Homebrew with RVM is the easiest way...
Homebrew installation:
https://github.com/mxcl/homebrew/wiki/installation
Here is a nice screencast with RVM:
http://railscasts.com/episodes/200-rails-3-beta-and-rvm

Rails 3 on Fedora issues

I have been trying to get Rails 3 installed in Fedora, it requires Ruby to be 1.8.7 or 1.9.2. Fedora official yum repos have Ruby 1.8.6 which is of no use. So I decided to compile it myself from the source, downloaded the source, compiled it and installed it successfully.
But this weird thing happens after the install, sudo gem or sudo ruby are not working, it just returns saying command not found.
which ruby
/usr/local/bin/ruby
ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
sudo ruby
sudo: ruby: command not found
sudo echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
Am I missing something, why doesnt it find ruby when its in the PATH?
check your PATH variable (set in your .bash_profile or .bashrc file, add /usr/local/bin to the front of the PATH:
PATH=/usr/local/bin:$PATH
I'd recommend that you check out RVM -- so far the best way to install and switch between different Ruby versions and to maintain Gems independently for each version!
https://rvm.io
Using RVM is much easier than compiling by hand, and it keeps all your Gems organized by Ruby version!
There's also a RailsCast on it: http://railscasts.com/episodes/200-rails-3-beta-and-rvm

Resources