1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Rep Power

    How to tell Terminal which version of Ruby to use?


    I have two related questions that I was hoping someone could help out with.

    1. I recently installed Ruby 1.9.2 on my Mac (running Snow Leopard 10.6.4) and I havenít been able to figure out how to get Terminal to use the new Ruby as a default, rather than the factory-installed Ruby 1.8.7. The old Ruby 1.8.7 is located in my ~/usr/bin/ruby directory while the new Ruby 1.9.2 is in ~/usr/local/bin/ruby. Someone said that I need to put the new version of Ruby's directory in the PATH prior to the old version's directory so that the system looks there first - is this correct? If so, can anyone provide step by step instructions on how to do this?

    2. Iíve created a new directory but canít seem to figure out the correct way to add that directory to my PATH using the Terminal bash shell. The directory containing my program ("Ruby_Programs") shows up in the PATH but when I try to run "ruby newprogram.rb" from the command line it results in ":ruby: No such file or directory -- newprogram.rb (LoadError)".

    Any help would be greatly appreciated. Here is my current PATH:

    $ echo $PATH
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Constant Limbo
    Rep Power
    $PATH has nothing to do with arguments to programs, it has to do with the locations of programs themselves. For instance:
    $ ruby my_prog.rb
    Is running teh ruby executable (the one that relies on the $PATH variable) with an argument of my_prog.rb. If you want my_prog.rb to execute drop the ruby, make it executable, and ensure that you either have the program location in your $PATH or provide a full pathname.
    $ my_prog.rb  # needs to be in your $PATH
    $ /usr/local/bin/RubyPrograms/my_prog.rb  # no need to worry about $PATH here
    To edit your path you set an environment variable. This varies from shell to shell, this example is bash-specific (should be fine for your Mac).
    $ echo $PATH
    $ PATH="/some/path/here:${PATH}"
    $ echo ${PATH}
    To make a change like that permanent, you put it in your config/rc file. For example in ~/.bashrc you can add the following line
    export PATH="/some/path/here:${PATH}"
    Regarding which version of Ruby to use, the $PATH variable is searched from front to back and delimited by ':' characters. So you want /usr/local/bin to appear earlier in the list.

    If you are interested in an alternative you can also google for bash alias command.
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog

IMN logo majestic logo threadwatch logo seochat tools logo