What Makes an App the System Default?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers What Makes an App the System Default?
# 1  
Old 02-15-2013
What Makes an App the System Default?

Hi!
I'm not sure how, (or if), Apple updates stuff in the standard unix installation of OS X, but whenever I have occasion to check a version number of something in my standard install, it is outdated. Normally, I will then install the newer version via ports, which usually becomes the default. Being a long-time Mac user, I am used to these things happening automagically, and I don't always give it much thought.
But today, I wanted to install a little Scrabble Solver script I found, and it required ruby 1.9.2, or better. I checked my version in /bin, and found I had 1.8, so I installed ruby19 via ports. Then I tried to install the script.
Code:
$ sudo gem install scrabble-solver
ERROR:  Error installing scrabble-solver:
	scrabble-solver requires Ruby version >= 1.9.2

$ which ruby
/usr/bin/ruby

$ ls -l /opt/local/bin/ |grep ruby
-rwxr-xr-x   1 root  admin     9024 Feb  6 11:21 ruby1.9
$

Why didn't ruby 1.9 become the default? How does the system determine which app is the default? I used to think it simply accepted the first one it came across in my PATH, but clearly that is not the case.
Code:
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/MacGPG2/bin:/usr/X11/bin

I haven't had occasion to invoke ruby myself, but I suppose other stuff uses it. Is there any reason I couldn't just set an alias to ruby 19 in my bash config? Would that solve the problem in terms of installing this script?
TIA!
# 2  
Old 02-15-2013
I notice with satisfaction you still tenaciously learn UNIX despite my efforts to let the subject look boring and hard to grasp - good!
Quote:
Originally Posted by sudon't
Code:
$ sudo gem install scrabble-solver
ERROR:  Error installing scrabble-solver:
	scrabble-solver requires Ruby version >= 1.9.2

$ which ruby
/usr/bin/ruby

$ ls -l /opt/local/bin/ |grep ruby
-rwxr-xr-x   1 root  admin     9024 Feb  6 11:21 ruby1.9
$

Why didn't ruby 1.9 become the default? How does the system determine which app is the default? I used to think it simply accepted the first one it came across in my PATH, but clearly that is not the case.
Code:
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/MacGPG2/bin:/usr/X11/bin

To me it looks like the problem is the name: the new ruby in "/opt/local/bin" is not named "ruby", but "ruby1.9". If you issue which ruby1.9 you would probably see this one, but if you search for "ruby", you get the one in "/usr/bin" simply because it is the only "ruby" you have.

Now, why ruby decided to install as "ruby1.9" and not as "ruby" i don' know. I don't know Macs version of UNIX at all, so i can only tell you what is the possible reason for the problem, not how to solve it.

You can, of course, try to solve the problem brute-force:

Rename "/usr/bin/ruby" to something else, say, "/usr/bin/ruby1.8". Then create a softlink:

Code:
ln -s /opt/local/bin/ruby1.9 /usr/bin/ruby

Whenever "ruby" is used, this link is followed and your new executable is used. If this works, i don't know. (There might be libraries or whatever necessary for ruby to work and it will probably not find them in any arbitrary place.) If this is not working, just delete the softlink and move the original ruby back into place:

Code:
rm /usr/bin/ruby
mv /usr/bin/ruby1.8 /usr/bin/ruby

I hope this helps.

bakunin
# 3  
Old 02-16-2013
Apple

Quote:
I notice with satisfaction you still tenaciously learn UNIX despite my efforts to let the subject look boring and hard to grasp - good!
What? Unix is great fun! I just can't get anyone else to agree.
Quote:
I don't know Macs version of UNIX at all...
I am told it's mostly like FreeBSD.
Quote:
Code:
ln -s /opt/local/bin/ruby1.9 /usr/bin/ruby

Well, we want ruby1.9 as the target file, right? Shouldn't it be the opposite?
Here's a couple thoughts I've had:
Will it break anything if I simply change the names? Change ruby to ruby1.8, and change ruby1.9 to ruby? I guess it would likely break ports.
Or what if I invoked gem1.9 to install the script? Actually, let me try that.
Code:
$ sudo gem1.9 install scrabble-solver
Password:
Fetching: scrabble-solver-0.2.gem (100%)
Successfully installed scrabble-solver-0.2
1 gem installed
Installing ri documentation for scrabble-solver-0.2...
Installing RDoc documentation for scrabble-solver-0.2...

Two heads are better than one! It never occurred to me that the names were the problem. I wonder why they attached the version number to the filename in this case?
Well ok, enough of that. I'll no doubt be back once I've had a chance to look closely at this scrabble-solver script. It doesn't look much like a ksh script, but I can already see it looks in the wrong place for the dictionary.

Last edited by sudon't; 02-16-2013 at 01:30 PM.. Reason: new thought
# 4  
Old 02-16-2013
Quote:
Originally Posted by sudon't
I am told it's mostly like FreeBSD.
Frankly, i haven't ever used FreeBSD either. In fact, machines which occupy less than 1m³ of space are not to my liking.

Quote:
Well, we want ruby1.9 as the target file, right? Shouldn't it be the opposite?
Actually, no. We want "ruby1.9" to be reachable also via "ruby", so we have to create a link from the source "ruby1.9" to the target "ruby". At least this was what i had in mind. For a test i wanted to do as little change to the system as possible and hence the link instead of shuffling around files.

Quote:
Here's a couple thoughts I've had:
Will it break anything if I simply change the names? Change ruby to ruby1.8, and change ruby1.9 to ruby? I guess it would likely break ports.
No, it probably will not break anything, but again: as long as i am less than 101% sure what i do and which consequences it will have i try do be as reversible as possible, therefore the idea with the link. In practice your idea will do the same but in a wee bit more intrusive way.

In general a systems administrator should avoid changes to the system like the plague. This is why self-written utilities go to /usr/local/bin instead of /usr/bin: to avoid mixing system-provided executables and your own. This way your system stays as "clean" as possible and you never will experience version problems, when newer system tools overwrite your hand-hacked ones during a version upgrade.

Quote:
It never occurred to me that the names were the problem. I wonder why they attached the version number to the filename in this case?
Probably for the same reason: avoiding version conflicts. When you have a binary "ruby", which is in fact "ruby v1.8" and you replace it with another binary which is "ruby v1.9" it might be that some program using it depends on some feature ruby 1.8 exhibits and ruby 1.9 doesn't. You are in deep kimchi in such a case.

Some programs (java under AIX for instance) install every version into a different path and use environment variables to select a certain version. Others have the version included in their executable's names and create a link to the "normal" name with the default version: there will be /usr/bin/prog1.0, /usr/bin/prog1.1 and /usr/bin/prog2.0 and a link /usr/bin/prog which points to, say, /usr/bin/prog2.0. Every program using "prog" will be directed to prog2.0 but every other version can be used too by selecting it explicitly. To change the default one just removes the link and creates it anew pointing to another version.

Quote:
Well ok, enough of that. I'll no doubt be back once I've had a chance to look closely at this scrabble-solver script. It doesn't look much like a ksh script, but I can already see it looks in the wrong place for the dictionary.
Good. I am looking forward to. Post the script (or relevant parts) and we go over it.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Programming

Wuhan Coronavirus Status App for China - Rapid Prototype using MQTT and the IoT OnOff IOS App

With a little bit of work, was able to build a nice "Wuhan Coronavirus Status" app using MQTT and the IoT-OnOff app. More on this technique here: ESP32 (ESP-WROOM-32) as an MQTT Client Subscribed to Linux Server Load Average Messages The result turned out nice, I think. I like the look and... (10 Replies)
Discussion started by: Neo
10 Replies

2. UNIX for Dummies Questions & Answers

chmod ug-s /System/Library/CoreServices/RemoteManagement/ARDAgent.app/.... NOT PERMITTED

After much reflecting I decided that I don't want to have a remote managemente in my computer and I digited in Terminal from the Administrator Account: chmod ug-s /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDAgent But the answer is: NOT PERMITTED Why? Is it not... (6 Replies)
Discussion started by: Vera
6 Replies

3. UNIX for Dummies Questions & Answers

Loading App as the System starts

Hi Folks! I am a Mac OS X user, and have written an Applescript application that I would like it to be run before the user logs in. I have tryed leaving the Mac on the "Login Screen", that screen just before you log in typing name and password, and logging using ssh from another Mac on the... (0 Replies)
Discussion started by: fundidor
0 Replies
Login or Register to Ask a Question