2

I want to execute a ruby file using windows 10 powershell. In my powershell terminal, when I type

ruby test.rb 

I receive

ruby: The term 'ruby' is not recognized as the name of the cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a 
path was included, verify that the path is correct and try again. 
At line:1 char:1
+ ruby test.rb
    +Category Info        :ObjectNotFound: (ruby:String) [], 
    CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

These commands don't work either

ruby.exe test.rb
rb.exe test.rb

I'm in the right directory. I suspect the problem has to do with PATHs, but I don't understand PATHs yet. I have been trying to execute .rb files in both Powershell and my beginner IDE, Visual Studio Code.

Thanks

3 Answers 3

1

It is absolutely a problem with your path. Try this:

$Path = 'C:\Path\to\ruby.exe'

& $Path args

Make sure your root folder for ruby.exe is in the $env:Path variable.

$env:Path -split ';'
Sign up to request clarification or add additional context in comments.

6 Comments

@John If this fixed your problem, kindly mark it as an answer for future readers.
I am still trying to fix this problem. I input '$Path = 'C:\Path\to\ruby.exe' in Powershell and hit enter. On the next line I tried both '& $Path args' and, after that did not work, '$Path args'. Both of those returned messages. I will update this thread after I've put in a bit more research and work.
@John $Path args won't work, & $Path args should. If you're going to try that way, use the path to the exe without quotes so it's interpreted as an exe properly.
No success yet. In powershell, I navigate to PS C:\> and type $Path = 'C:\Path\to\ruby.exe'. I hit enter. On the next line, & $Path args. This returns the following error message: & : The term 'C:\Path\to\ruby.exe' is not recognized as the name of a cmdlet ... Here is a screenshot of the error message: pasteboard.co/GWU3WEg.png
@John You weren't supposed to use that string literally.. It's a representation of your install location for rb.exe/ruby.exe
|
1

For me I had to kill all instances of powershell -- in my case vscode then relaunch and it picked up the new path environment variables and ruby worked!

Sometimes a full restart is what the doctor prescribed.

I've also had cases where you had to run the program as an administrator to work and have the proper updated new path variable.

Comments

0

In powershell, navigate to the directory where your ruby file is stored. It will look something like this C:\Users\Joe\Desktop\Ruby_Practice_folder>

Type

#!/usr/bin/env ruby

Hit enter. Type

ruby your_ruby_file.rb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.