Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does MacPorts install packages? How can I activate a Ruby installation done via MacPorts?

After trying to install ruby19 on my machine (PPC, Mac OSX 10.5.7) using the following commandline

sudo port install ruby19

the version of ruby didn't change

ruby -v => ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]

I assume that i have two versions of it installed on my mac, but how do i use the latest one now?

like image 429
Julian Weimer Avatar asked Dec 03 '22 14:12

Julian Weimer


2 Answers

By default, the Ruby 1.9 port in MacPorts installs the Ruby binary in /opt/local/bin/ruby1.9. It appends a 1.9 to avoid stomping on Ruby 1.8.7 libraries and gems, since not all gems are compatible with 1.9 yet. So you have to launch Ruby 1.9 with ruby1.9 (and irb1.9, etc.)

If you don't want to have to do this, you have two options:

  1. Alias ruby to ruby1.9 in your shell config file.
  2. Install the Ruby 1.9 port with the +nosuffix variant. Be warned, however, that if you have installed Ruby 1.8 via MacPorts, installing Ruby 1.9 via MacPorts without the 1.9 suffix may cause conflicts (with gems, etc.).
like image 84
mipadi Avatar answered Dec 22 '22 00:12

mipadi


To use a specific ruby version if you have two versions installed you can either specify an absolute path to the one you want. E.g. /your/path/to/ruby Or you can change your PATH setting in your .profile

you can type

which ruby

to see the path to the ruby executable that is used at the moment.

using

echo $PATH

You can see the current PATH setting. You have to prepend the path to your new ruby binary to the PATH so that it will be found before the other one.

As ayaz already mentions, the default location of your macports stuff is in /opt/local. If you add /opt/local/bin in front of your path it should be fine. (Make sure to start a new terminal window after the change - they will not be picked up in your current session unless you explicitely 'source' the .profile file again)

One note of caution: after prepending /opt/local/bin to your path the shell will always prefer binaries in there to binaries found later, this can be an issue if you depend on specific versions in /bin, /sbin or /usr/sbin -- depending on your situation this means that you should not do it (if your computer is processing sensitive data and/or in a bank or something) or just have to remember that it could be an issue (if your computer is a normal development machine).

See http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variable/ if you need some more hints on how to set your PATH on osx.

like image 35
Simon Groenewolt Avatar answered Dec 22 '22 00:12

Simon Groenewolt