Yes, that’s right, ladies and gents. Thanks the hackery of a great many individuals (no, I am not among them), just this evening, I ran the following on my iPhone:
ruby -e “10.times { puts ‘foo’ }”
You can guess what happened.
Here’s how you do it, in short order, with minimal agony: Use the unofficial Installer.app developed by some folks at NullRiver. That’s it! From there, install the “Community Sources”, install “Ruby”, the BSD extensions, and “Mobile Terminal” and then go rubify yourself.
Ironically, this is not officially a product of theirs — more than likely because it is unwise to declare third party software for the iPhone as an official product at this tenuous time.
I wonder how long it will be before some intrepid Ruby coder works out a way to get to UIKit easily from Ruby and gens up some rdoc for it. I wonder if SWIG would help here?
Just for giggles, I tried:
ruby -e ’start=Time.now;a=1;b=1;1000000.times {a=a+b};puts a;puts “time: #{Time.now - start}”‘”
On my 2.16 Ghz Core Duo Macbook Pro, this took 0.280763 seconds. On the iPhone, this took 10.060393 seconds.
Looks like a speed difference of a factor of 50 for this simple computation.
Update: Um, ok, maybe it’s closer to 36 than 50.



17 comments ↓
Isn’t that more like a factor of ~35? You make the iPhone worse than it is.
Doh! Sure is. That’s what I get for doing a super-quick calculation in my head before hitting the sack!
try running “irb”, “erb”, or something simple like ruby -e ‘require “thread”‘
it segfaults or dies with BUG.
i can’t get irb to work, either, but i have been able to write and execute basic ruby programs
I followed your direction exactly, but keep getting “zsh: command not found: ruby”
I am working out of /usr/local/bin
Any advice you can offer is greatly appreciated.
Kent: I should have said “./ruby”. Remember that /usr/local/bin won’t be in your PATH unless you explicitly put it there first.
Can you tell I don’t do much from the command line? Thank you very much! Works like a charm.
Sorry to ask such a stupid question, but how can I permanently add this to the PATH? I modified my profile and it doesn’t seem to do the trick.
Kent: Not stupid at all. Now let me see if I can answer your question seeing as how I’ve never used ZSH ;).
At least you supplied the first clue with the error message; I didn’t know that the shell was using ZSH!
A quick google turned up the ZSH FAQ here: http://www.faqs.org/faqs/unix-faq/shell/zsh/. I believe that section “3.2: In which startup file do I put…?” should answer the bulk of your question. I only very quickly perused the FAQ but here’s what I believe that you will need:
Create a file in / called “.zlogin”. Inside .zlogin, you will want one line that reads “export PATH=$PATH:/usr/local/bin”.
Here’s the catch: I haven’t figured out how to exit from VIM using the iPhone keyboard. Hell, I’m not sure that you can yet ;). As such, you will likely want to write your .zlogin file on your Mac (you are using a Mac, right? ;)) and copy it to the iPhone using iPHUC.
Happy hunting.
I created a .zlogin file right on the iPhone using MobileTextEdit. No luck.
Thanks for the help tho. Much appreciated.
FWIW, make sure that you put the file in the directory that is listed if you type “echo $HOME” on the command line. If that doesn’t work, then my bag o’ tricks is not looking so good. Perhaps “.zshrc” instead of “.zlogin”?
Kent,
I use .profile instead of .login or .zlogin:
Also, the nullriver installer seems to have moved everything to /usr/iphone/bin
In my .profile:
PATH=$PATH:/opt/iphone/bin export PATH alias ll=’ls -l’
Sorry that was /opt/iphone/bin…
Ken
I’ve been trying to modify the $PATH using pico on the iphone, but I can’t figure out how to save. Anyone? Also, anyone seen irb working on an iphone yet?
Thanks Ken, works fine.
cd ~
echo “PATH=$PATH:/opt/iphone/bin”>>.profile
(reboot) (ruby away)
since there’s just one user on the iphone (root), i just added /opt/iphone/bin to /etc/profile. quit the terminal and try again. type ‘echo $PATH’ to see if it shows up.
Sorry for asking an inexperienced question but I really want to run Ruby on my iPhone.
How do you create the “.profile” file? Like can you just use your computer notepad and save it with a special extension (.exe;.app;.rb…etc) or do you have to create it on the iPhone itself? Also what commands do you enter to copy the file to the iPhone in iPhuc because I typed in:
‘putfile .profile at /’
But it didn’t show up on my iPhone when I looked for it with squid and finder. Please help!!!
Leave a Comment