This question already has answers here:
What command opens Ruby's REPL?
(2 answers)
Closed 6 years ago.
When attempting to run ruby on Linux (ubuntu 14.04) I am not getting a prompt like I do in python (">>>".) Below is an example. I can run the ruby -v to obtain the version information and execute ruby code when the code file is an argument. When I run ruby without any arguments I get nothing and have to break out of it. Any ideas what I am missing?
james#james-Latitude-D830:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
james#james-Latitude-D830:~$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
james#james-Latitude-D830:~$ ruby
help()
quit()
^C-: Interrupt
python and ruby are different languages you can open prompt for python using python but incase of ruby you have to use irb to open ruby 'prompt'
james#james-Latitude-D830:~$ irb
2.3.1p112 :001 > #here you can write your ruby code
Ruby's repl is opened with the 'irb' command. Just using ruby would be for calling programs. See this answer for more details - What command opens Ruby's REPL?
or just google ruby repl (read, evaluate, print, loop)
Related
I'm not sure what Ruby version is being used on my device (macOS) by default.
ruby -v outputs ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
brew list ruby --versions outputs ruby 3.0.2
rbenv versions outputs
system
* 2.7.4 (set by /Users/nlakritz/.rbenv/version)
If ruby -v shows 2.6.3, then you are using the ruby which ships with the system by default. You can confirm this in several ways. Running the shell command which ruby will show /usr/bin/ruby. Checking your PATH will show /usr/bin earlier than the location of the homebrew or rbenv installations.
If you wish to run one of the others, you can put it earlier on the PATH or invoke it explicitly by giving the fully qualified name such as /usr/local/opt/ruby/bin/ruby myscript.rb. Another alternative which avoids twiddling the PATH variable is to use a shebang line at the beginning of different scripts pointing explicitly to the version to use with that script.
It depends what you mean by 'default'. If you're running a file with ruby filename then the version you are using is 2.6 (because you're running the same Ruby as ruby --version).
If you're running a file directly (eg. ./filename.rb) then it depends on the shebang line in the file. For example, the file could start with the line #!/usr/bin/ruby, so to check which version of ruby that file is running on, you could call /usr/bin/ruby --version.
Hopefully that helps, but I'm not 100% sure I understood what you're asking - so let me know :)
Try this:
$ which ruby
/usr/bin/ruby
$ irb
irb(main):001:0> RUBY_VERSION
=> "2.7.0"
So, rbenv is ignored, I think you're missing this in your path:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
ruby -v # should say 2.7 now
And if it says 2.7, you can add the export and eval commands at the bottom of your ~/.bashrc to load it every time you open a shell, thus kicking off rbenv override.
I would bet 2.6 for you, ie ruby -v.
Installed ruby 2.4.0 using RVM, but after typing ruby, the command just freezes indefinitely. Can be ctrl-C'ed out, but ruby never loads.
Ruby info:
ruby-2.4.0:
system:
uname: "Linux waffleboy 4.8.0-58-generic #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux"
name: "Ubuntu"
version: "16.04"
architecture: "x86_64"
bash: "/bin/bash => GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)"
zsh: "/usr/bin/zsh => zsh 5.1.1 (x86_64-ubuntu-linux-gnu)"
remote path: "ubuntu/16.04/x86_64"
rvm:
version: "rvm 1.29.2 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]"
updated: "23 minutes 20 seconds ago"
path: "/home/waffleboy/.rvm"
autolibs: "[4] Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X)."
ruby:
interpreter: "ruby"
version: "2.4.0p0"
date: "2016-12-24"
platform: "x86_64-linux"
patchlevel: "2016-12-24 revision 57164"
full_version: "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]"
homes:
gem: "/home/waffleboy/.rvm/gems/ruby-2.4.0"
ruby: "/home/waffleboy/.rvm/rubies/ruby-2.4.0"
binaries:
ruby: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/ruby"
irb: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/irb"
gem: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/gem"
rake: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin/rake"
environment:
PATH: "/home/waffleboy/.rvm/gems/ruby-2.4.0/bin:/home/waffleboy/.rvm/gems/ruby-2.4.0#global/bin:/home/waffleboy/.rvm/rubies/ruby-2.4.0/bin:/storage/anaconda3/bin:/home/waffleboy/bin:/home/waffleboy/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/usr/bin:/storage/programfiles/:/home/waffleboy/bin:/storage/programfiles/spark-1.6.2/bin:/home/waffleboy/.rvm/bin"
GEM_HOME: "/home/waffleboy/.rvm/gems/ruby-2.4.0"
GEM_PATH: "/home/waffleboy/.rvm/gems/ruby-2.4.0:/home/waffleboy/.rvm/gems/ruby-2.4.0#global"
MY_RUBY_HOME: "/home/waffleboy/.rvm/rubies/ruby-2.4.0"
IRBRC: "/home/waffleboy/.rvm/rubies/ruby-2.4.0/.irbrc"
RUBYOPT: ""
gemset: ""
Rvm list:
rvm rubies
=* ruby-2.4.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
I've tried reinstalling and installing ruby multiple times but it just doesn't seem to work.
Can anyone point me in the right direction? :) Thank you!
This is normal; it is a feature, not a bug.
Running ruby, without any parameters, causes the program to run and wait to receive input from STDIN (ending with an EOF character). It will not execute anything until it receives this information.
If you want to run ruby in interactive mode, (like when you run python), then use ruby's built-in irb ("interactive ruby") command.
Alternatively, if you just want to display some basic information about the ruby version installed then you can try commands like:
ruby -v # Display version information
ruby -h # Display help about usage, switches and features
If you're looking for a REPL to type Ruby code into, have it executed, and see the results, then you're looking for the irb command, not ruby.
ruby is for running files (eg. ruby my_file.rb), or without arguments will read a script typed into standard input, which will get executed when you quit ruby with cmd+D.
I'm Mac OS X 10.9.4 user and have system ruby version 2.0.0. Started learning ruby i've decided to get new version. I've done it using rvm get stable. It works almost fine except interactive mode.
When i call irb in terminal, i receive:
-bash: /usr/local/bin/irb: ##HOMEBREW_CELLAR##/ruby/2.1.1_1/bin/ruby: bad interpreter: No such file or directory`
ruby -v prompts ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
How can i fix it?
Answer was quite easy. Here was almost the same problem.
Solution:
Open /usr/local/bin/irb and configure ruby interpreter path. Mine was ##HOMEBREW_CELLAR##/ruby/2.1.1_1/bin/ruby and i only had to change ##HOMEBREW_CELLAR## to /usr/local/Cellar/
I suppose that another possible solution would be defining ##HOMEBREW_CELLAR## var, but i'm new to ruby and hence not sure.
I just installed pik into c:\bin. I typed in pik list, and it shows:
* 193: ruby 1.9.3p484 <2013-11-22> [i386-mingw32]
200: ruby 2.0.0p195 <2013-05-14. [i386-mingw32].
I typed in: c:\bin> pik use 200 and c:\bin>ruby -v and get the following error.
'ruby' is not recognised as an internal or external command, operable program or batch file.
What might cause this, and how do I resolve it to properly upgrade to Ruby 2.0?
It occurred cause RUBY is not a command that described for Windows Command Prompt.
You should first go the app you want interact with it.
For this, you should write the path of it in Command Prompt.
But I offer use Ruby Installer (http://rubyinstaller.org/downloads/) that's more comfortable.
It will install all the packages are required simultaneously
I am reading a book "Working with Unix Processes" which uses ruby to explain about unix/linux processes. This is my first time working with ruby. I tried an example to get resource limits on processes.
irb(main):001:0> Process.getrlimit(:CORE)
Errno::EINVAL: Invalid argument - getrlimit
from (irb):1:in `getrlimit'
from (irb):1
from :0
irb(main):004:0> Process.getrlimit()
ArgumentError: wrong number of arguments (0 for 1)
from (irb):4:in `getrlimit'
from (irb):4
from :0
But I can't seem to get "getrlimit" recognized (though it says I have wrong number of arguments if I don't supply any args). Haven't found anything on this on google or SO. Tried with :NOFILE, :CORE and others. Is there something I need to include/require to make getrlimit work. Environment:
Ubuntu 11.04 32 bit. Kernel 3.0.0-14
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
irb 0.9.5(05/04/13)
regards
Sorry .. never mind. It seems that IRB was running a previous version of ruby (1.8.7) which somehow didn't support the getrlimit (though according to all accounts on google, it should have worked). I had upgraded ruby to 1.9.1 but did not update the link from /usr/bin/irb to /usr/bin/irb1.9.1. So IRB was still running ruby 1.8.7. After updating the softlink of irb to v1.9.1, getrlimit is now working.