Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I not determine my ruby installation's version?

Tags:

ruby

nameerror

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?

like image 926
ehsangh Avatar asked Aug 09 '13 19:08

ehsangh


People also ask

What version of Ruby Do I have Windows?

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.

How do I know if Ruby is installed Linux?

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.


2 Answers

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
like image 138
Richard_G Avatar answered Sep 24 '22 10:09

Richard_G


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 or ruby --version.

like image 27
Arup Rakshit Avatar answered Sep 23 '22 10:09

Arup Rakshit