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

StackOverflow https://stackoverflow.com/questions/1333569

  •  20-09-2019
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top