Running Ruby Script - ruby

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.

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

Can't run ruby command on windows 10

Recently I am trying to install Ruby on my Windows 10. After the installation process whenever I am trying to run any ruby command such as to check the version of Ruby, I command ruby -v and I got Access denied notifications.
For better purpose I am giving the screenshot of the problem I am facing:
PS: I am using rubyinstaller-2.4.1-2-x64 to install Ruby.

Cygwin - can't run ruby command

When I run ruby -v in cygwin, it shows me the ruby which I have installed in windows. FYI - I never installed any ruby as a part of my cygwin installation.
But when I run gem list, I get the error:
/cygdrive/c/ruby/bin/gem:
C:/dev/ruby/bin/ruby.exe^M: bad interpreter: Permission denied
I Googled and found this problem a lot. But there is no one who explained what it means and why it happens. Can someone please answer those questions for me and help me to fix this problem?
Thank you very much !
Under cygwin, your best bet is to run the cygwin version of ruby, installed using the cygwin setup tool.
You can use regular ruby, but you will have interoperability issues like this.
What you are seeing here is the shell complaining about a ^M at the end of the "shebang" line of the gem script (first line that tells it what interpreter to use). This ^M is an artefact of the windows environment where all lines end with this character as well as just the newline character that unix uses on its own.
You could solve this problem by removing the newlines e.g. by using dos2unix command on gem but it won't be long before you run into further issues ...

Geektool Ruby script fails to load gems

I'm trying to use Ruby to write a couple scripts for geektool. However, I've found that geektool can't process
require "some_gem"
Where does geektool execute shell commands? Is it possible to make gems available to to it there, or force the scripts to run in the normal shell environment? Someone attempted to answer this question [here][1].
/Users/Dave/.rvm/bin/rvm use 1.9.3-p0 > /dev/null
/Users/Dave/.rvm/rubies/ruby-1.9.3-p0/bin/ruby ~/foo.rb
However, this fails with RVM throwing an error, that it is not an application, and that I must enable login.
I'd really appreciate some help on getting Ruby gems to work in geektool

The command "ruby" does nothing on my Mac

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.

Resources