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

后端 未结 4 1444
一向
一向 2020-12-29 17:03

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

相关标签:
4条回答
  • 2020-12-29 17:09

    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.).
    0 讨论(0)
  • 2020-12-29 17:10

    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.

    0 讨论(0)
  • 2020-12-29 17:23

    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.

    0 讨论(0)
  • 2020-12-29 17:25

    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.

    0 讨论(0)
提交回复
热议问题