How Does MACports Install Packages? How to Activate a Ruby Installation Done via MACports

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

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.

Installing ruby using MacPorts

Ruby is installed by default in every mac. However, it's ruby 1.8, which is very old and shouldn't be used in any of your projects.

Take a look at rvm.

It will allow you to install several versions of ruby in the same system.

So, for example, you can do the following :

rvm use 1.9.3
ruby -v #=> ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin12.2.0]
rvm use 2.0.0
ruby -v #=> ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]

Using rvm, you can install any new version of ruby using the following :

rvm install 2.0.0-p0 #=> This will install Ruby 2.0.0
rvm install jruby #=> This will install jruby

And so on

Problems with Macports Ruby19 Install

It turns out I already had a macports install of ruby (1.8.7).

I uninstalled all my macports ruby19 editions sudo port uninstall ...

deactivated the active version sudo port -f deactivate ruby

and installed the version of 1.9.3 with no suffix

sudo port install ruby19 +nosuffix

I received this error:

Image error: /opt/local/bin/gem is being used by the active rb-rubygems port. Please deactivate this port first, or use 'port -f activate ruby19' to force the activation.

so ran sudo port -f activate ruby19

now when I run rails server I get:

/opt/local/lib/ruby1.9/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /opt/local/lib/ruby1.9/1.9.1/rubygems.rb:1231:in `gem'
from /opt/local/bin/rails:22:in `<main>'

I then updated my gem package and rails:

sudo gem update --system
sudo gem uninstall rubygems-update
sudo gem install rails
sudo bundle install

result:

Your bundle is complete! Use 'bundle show [gemname]' to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

A useful discussion here on macports and ruby paths: How does MacPorts install packages? How can I activate a Ruby installation done via MacPorts?

Many people recommend RVM https://rvm.io/, but for me I just need 1.9.2 running for now.

ruby 1.9 and 1.8.7 installed how do I make app use 1.8.7

Firstly: switch to rvm it's excellent for ruby management

If you don't want to then I believe you can remove the ruby package with (if installed with macports) with the following:

sudo port uninstall ruby19

To start using the new version of ruby you need to find where it is installed (it's something like /opt/local/<...>)

Then go to the Binary folder and add it to path.

export PATH=/opt/local/<...>:$PATH

Removing the old one, you might need to change some env variables as well.

Use RVM

EDIT: added sudo to port command and changed standard location

Cannot port install Ruby

To fix this problem what I had to do was go to the MacPorts webpage, download the new Mavericks MacPorts package, and run through that installation. I thought that doing a port -v selfupdate would update my current MacPorts to the Mavericks OS MacPorts but unfortunately it did not.

Why does Macports take FOREVER to build simple packages?

If you are running on an Intel Core 2 Duo you can double the speed of your builds by changing the Macports config option located here:

/opt/local/etc/macports/macports.conf

# Number of simultaneous make jobs (commands) to use when building ports
buildmakejobs 2

I was kicking myself when I discovered this AFTER I rebuilt gcc ;)

This option will allow you to use both cpu's for building packages.



Related Topics



Leave a reply



Submit