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

15,091

Solution 1

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.

Solution 2

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.).

Solution 3

Just a quick clarification about MacPorts. Ayaz is right that, by default, MacPorts will install things in /opt/local. (This makes it easy to globally uninstall later, if you want, and it keeps MacPorts packages out of the way of OS X packages.)

When you install MacPorts, it will normally edit your $PATH (and your $MANPATH) for you by updating your user's .profile (creating it, if it doesn't already exist).

As a precaution, the installer will create a backup of the original .profile in case you want to roll back the changes (or if you completely uninstall MacPorts later). Here's an example from a random machine at work.

admin ~ $ ls .profile*
.profile  .profile.macports-saved_2009-08-03_at_14:55:56

If you look in .profile you should see something like this:

##
# Your previous /Users/admin/.profile file was backed up as /Users/admin/.profile.macports-saved_2009-08-03_at_14:55:56
##

# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate MANPATH variable for use with MacPorts.
export MANPATH=/opt/local/share/man:$MANPATH
# Finished adapting your MANPATH environment variable for use with MacPorts.

If your $PATH hasn't been updated, you should adjust it, since otherwise, you will have trouble using the port tool and the software you install via MacPorts.

Solution 4

I am inclined to think that macports usually keeps all of its stuff inside the /opt/local directory. I am using Leopard, and I have it inside that directory. You may want to look in there, particularly inside /opt/local/bin, to find the ruby binary you are looking for.

Share:
15,091
Julian Weimer
Author by

Julian Weimer

Updated on June 24, 2022

Comments

  • Julian Weimer
    Julian Weimer almost 2 years

    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?

  • Julian Weimer
    Julian Weimer over 14 years
    thx for the info, and i think macports had done that stuff already for me, because as i looked up the name of it, using ruby 1.9 is as simple as typing "ruby1.9 ..." into the terminal export PATH=/opt/local/bin:/opt/local/sbin:$PATH
  • atomicules
    atomicules over 12 years
    An alternative to adding an alias is to create a "bin" directory in your home folder and in there create links to the macport ruby ln -s /opt/local/bin/ruby1.9 ruby and gem ln -s /opt/local/bin/gem1.9 gem then source this first in your path export PATH=~/bin:$PATH. The advantage of this is that it will allow MacVim to pick up the right version of Ruby (it doesn't recognise the aliases, only the $PATH).
  • beporter
    beporter about 11 years
    The method of using the +nosuffix variant has been superseded by a new MacPorts syntax (as of v2.1.3?): port select --set ruby ruby19. This supposedly applies to any package that has multiple "versions" available, although it appears that the package's maintainer needs to implement support for this individually. The select' command sets which of those versions will be available without the suffix (/opt/local/bin/ruby` instead of /opt/local/bin/ruby19.)