The command "ruby" does nothing on my Mac - ruby

I can't get the Ruby interpreter to run on either of my Macs (one MacBook and one MacBook Pro, both running Snow Leopard). When I run it, by typing ruby in Terminal, nothing happens. It just sits there. I can kill it by pressing Ctrl+C, but that's it. I know the Ruby process is running, since I can see it in Activity Monitor, and running ruby --version works fine.
I have tried the following, all to no avail:
I have some bash customizations, so I tried disabling them, but that didn't help.
I installed a new copy of Ruby 1.8.7 using MacPorts, but that one had the same problem.
I tried quitting and restarting the Terminal application.
Some other information that might be useful:
I'm trying to run the version of Ruby that comes with Snow Leopard.
I have installed Apple's developer tools.
Other interpreters (Python, Io, etc.) work fine.
I spent a while tonight searching for this problem online, but haven't found any discussion of it. I'm at a loss for what could be causing it, so any help anybody can provide would be greatly appreciated.

Ruby command itself will just behave the way you said, either provide it with script file or use the -e option:
ruby -e ' puts "hello world" '
However I suspect that you want the IRB(interactive ruby). Run irb in your shell.

What are you trying to do, exactly? The ruby command expects input, in most cases a file that contains Ruby code that you want it to run. In that case you have to specify the name of the file:
> ruby my_ruby_file.rb
If instead you want to run the interactive Ruby shell, i.e. the REPL console that you can type Ruby code into and have it executed each time you press enter, the command you want is irb.

Related

All Ruby commands immediately close

I did a fresh install of Ruby 2.6.5 x86 on my Windows Server 2016 64-bit machine (previously had 64-bit 2.6.5 and some 2.4.5 version. Can't remember if it was 32/64 bit). I did NOT run the MSYS install at the end. I see the PATH has been updated to include ruby. When I type ruby in a command prompt nothing happens. I do not get a message saying ruby is unrecognized. It actually looks like ruby is going to open (I see mouse loading animation) in the command prompt but then immediately terminates. How do I fix this?
As requested here are the results of where ruby:
ruby
is not interactive interpreter, it is only used to run complete scripts like this:
ruby script.rb
Use
irb
for interactive programming. You also can run a script and then poke around inside it with
irb -r ./script.rb

Running Ruby Script

Can someone help me out?
So I installed Ruby 2.4 on my PC via the RubyInstaller from https://rubyinstaller.org/downloads/. I have Windows 10.
I've used Ruby 2.2 and this 2.4 version seems very different.
When I installed it, it created an MSYS2.exe and it now opens a bash shell.
I've not used a bash shell in a very long time (14+ years). I can navigate fine in it. But I receive the following error message when I try to run a ruby file:
$ ruby r1.rb
bash: ruby: command not found
I'm not sure how to run a ruby script on the bash shell from MSYS. I have added the C:\Ruby24-x64\bin to my environment variables. But I still get the same message.
I'd appreciate some assistance if possible. Thanks.

Installing Jekyll on Linux Mint, Never recognized

I'm very much a linux noob, so pardon me if I overlooked something trivial.
http://img51.imageshack.us/img51/8081/53bv.png
I installed RVM, and ruby, and am using ruby 2.0.0. In the regular terminal (Ctrl+Alt+T), installing jekyll seems to do nothing (even though it says success).
But for some reason if I do it in the Ctrl+Alt+F1 shell, it works fine and as I'd expect it to. I have rebooted, re-installed ruby, still the same.
Is there something I need to add to my bashrc file? or my PATH? If so could someone please be so kind as to tell me exactly what to add and how to add it?
Got some insider help.
I guess in the terminal profile settings there is a Run command as a login shell that needed to be checked. Everything works as normal now.

No progress installing ruby via macports. How long should this action take?

I'm in the process of installing ruby using macports. I typed the following command into terminal:
sudo port install ruby
Terminal responded by returning some lines that indicated the action was working, then it just stopped returning any new lines. I typed:
which ruby
and didnt get a response, so I closed the terminal window and consequently ended the processes.
I opened a new terminal window and re-typed the original install command and now I get the following message:
Waiting for lock on /opt/local/var/macports/registry/.registry.lock
How should I proceed from here? Should I just wait? If so, how long? Will terminal try to complete this action twice? How can I know if it's working?
A more appropriate thing to check, when you've seen no progress, is your system's activity.
On Mac OS, you could either open "Activity Monitor" and sort by CPU, or open a terminal and type top -o cpu. Watch for some app showing consistent activity, especially something with "port" in the name.
To deal with the lock... odds are REALLY good it's stale since you cut it off at the knees by closing the terminal, so use sudo rm /opt/local/var/macports/registry/.registry.lock to remove it and retry if you want.
I will recommend RVM for installing new versions of Ruby. It's really convenient. Before you jump into RVM read the "Installation" and "Rubygems" pages entirely, and after installing RVM type rvm notes and follow the directions it spits out.
Finally, do not, under any circumstance, no matter how good an idea it seems to be, try to replace or upgrade the system version of Ruby installed by Apple. Apple installed it for their own use, and messing with it invites bad juju.
"Waiting for lock on /opt/local/var/macports/registry/.registry.lock" means MacPorts is already running and doing things. You could check for any running "port" processes in Activity Monitor. Wait until these tasks are finished (or terminate them if you don't care that they don't finish) before trying to do other things with MacPorts.
ps -A | grep tclsh if you can't find the running process so you can kill it.
A more recent way to install Ruby is via RVM. Not a direct answer to you question, but I would highly recommend it.
Here is another vote for rvm. If you are like me, and you program on a mac, but you deploy to some other *nix, then you can make sure you have the same version of Ruby (and Rails, and gems) on each, using rvm's gemsets.
Also, you can switch among gemsets easily, so that if you find a gem that you can't get working right with Ruby 1.9.2, then you can switch to 1.8.7 or some such whilst you try to figure it out. Stuff like that.
As far as I'm concerned, you can jump right in on your mac (as yourself, not using sudo) with rvm install 1.8.7 or rvm install 1.9.2. Then make sure you switch to use the correct rvm, and make the one you want your default, and you're golden. If it doesn't work, delete it - all the gemsets will be installed below your home directory in .rvm/*
The pain you are going through now will resurface when you try to keep your system version of Mac's ruby working with all the stuff you write -- RVM is definitely easier than using Mac's Ruby.
In addition to what the Tin Man mentioned, if other "lock" errors start coming up, I found disabling the internet connection for a moment was helpful to stop all port processes that were occurring.

Installing Ruby on Mac 1.9.2, still getting 1.8.7 even though path changed

I'm on a Mac running 10.6.4 Snow Leopard, and apparently ruby comes ready to go. But I'm new to Ruby, trying to learn the Rails framework, and so i decided to install the latest version 1.9.2. I followed the instructions here, but after I compile and install, when I run ruby -v I'm still getting 1.8.7. Anyone can help a noob out?
When I use which ruby I am getting usr/local/bin/ruby, so the path has changed and is correct.
UPDATE:
It seems I was having issues because I was using two login files to set my path (.bash_login and .profile). You can only use one, and the first one that exists and is readable will be used. I eventually switched to RVM and used .bash_login to load RVM into shell.
Well, the sw isn't lying to you. So something is not as you expect.
Try /usr/local/bin/ruby -v and see what version it is.
Added: Also, try locate ruby|more to see where the ruby files are on your system.
You may need to change your path to use your newly installed copy of ruby.
Added more: did you add the Path to your ~/.profile file as the instructions tell you to do in step 1?
Did you restart your terminal session after changing the ~/.profile file? (Quit and restart terminal.)

Resources