Reputation: 421
Every time I type ruby
and hit Enter at my terminal, it just hangs for seemingly forever. This is happening for the default Yosemite install and after I installed with rbenv, using Homebrew (which works fine), using "Ruby on Rails development setup for Mac OSX".
My current Ruby version is 2.2.2, ruby -v
works, and I didn't have this problem when I was using OS X Mavericks.
Has anyone else had this problem and/or found a solution? My google-fu doesn't seem to be strong enough.
Upvotes: 0
Views: 224
Reputation: 160551
When you enter ruby
at the command-line, it's supposed to "hang forever". It's waiting for you to give it instructions. You can use CTRL+D to get it to stop waiting:
> ruby
puts 1 + 1
2
I then did CTRL+D and returned to the command-line prompt.
Instead though, we don't use Ruby like that. If we want to use it interactively, we use IRb which comes with Ruby. It's the "interactive" Ruby:
> irb
Welcome to IRB. You are using ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin13]. Have fun ;)
>> 1 + 1
2
>> 'foo'.squeeze('o')
"fo"
If we want to run a Ruby script, we use something like:
ruby /path/to/script
and Ruby will load and run it.
I'd recommend reading some Ruby tutorials and learn how the language works before trying to use Rails. Rails uses deep Ruby magic and how Rails works will be unfathomable to you until you do understand better how Ruby is used and how it works and what it can do.
If you're using rbenv to manage your Ruby, then when you enter rbenv versions
you should see the Rubies it manages listed:
rbenv versions
system
1.9.3-p551
* 2.2.2 (set by /Users/tinman/.rbenv/version)
If you don't, either rbenv isn't in control of Ruby, or you haven't installed any using rbenv. rbenv global system
will tell it to use whatever you have installed by default in the system, based on your PATH.
rbenv's documentation and built-in help go over this so if the problems continue then you need to closely examine your install and setup, because 90% of the problems we see using a sandboxed Ruby are due to people not paying attention to the directions, or using the wrong ones, and not completing the installation.
Upvotes: 3