When I run ruby -version
I get:
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
-e:1: undefined local variable or method `rsion' for main:Object (NameError)
What could be wrong?
Step 1: Check Ruby Version First, check if you already have Ruby installed. Open the command prompt and type ruby -v. If Ruby responds, and if it shows a version number at or above 2.2.
One way open the terminal window (sometimes called a "shell" or "bash shell") is to select Applications > Accessories > Terminal. Run the command which ruby. If you see a path such as /usr/bin/ruby, Ruby is installed. If you don't see any response or get an error message, Ruby is not installed.
Use either ruby -v or ruby --version. It's parsing the -version into rsion.
Either of these two work. Count the number of dashes:
ruby -v
ruby --version
When you provide a single dash with "version", Ruby sees this:
ruby -v -e rsion
There is a -v option and a --version option, but no -version option. (Count the dashes.) Look undefined local variable or method 'rsion' for main:Object.
From this thread, actual reason is much clear :
If you run
ruby -version
, since you only use a single dash, the word 'version' isn't treated as a single flag but instead as a list of flags. In this case, it picks up the -v flag, which prints the version information. Then it tries to process the e flag, which basically says "the rest of this line is a ruby script to execute." So ruby faithfully attempts to parse "rsion", which is where you're getting the NameError.To just get the version info, you can do
ruby -v
orruby --version
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With