Ruby Irb reacts strangely to control keys - ruby

I'm (extremely) new to Ruby, having started today.
I just moved from my system's Ruby 1.8 installation to Ruby 1.9, compiled from source. In doing so, irb has taken a turn for the worse. It reacts in a most unfriendly way to the non-alphanumeric control keys:
UP key prints: ^[[A
DOWN key prints: ^[[B
DELETE key prints: ^[[3~
...and so on. The main result of this for me is that I have no access to previously issued commands. Nor does tab-completion work; though none of this seems to be an issue with Wirble - the same happens when I remove my ~/.irbrc.
I'm using:
Ubuntu 9.10
GNOME Terminal 2.28.1
ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]
Irb version 0.9.5 (05/04/13)
Any ideas? :(

This could be a readline issue. You could try installing libreadline and libreadline-dev packages and rebuild Ruby after that, see if it helps:
apt-get install libreadline5 libreadline5-dev

If you use OS X Snow Leopard and have the same problem there is a description how to fix it here: http://snippets.dzone.com/posts/show/10511

readline is the correct answer. just wanted to say that for os x, you can install readline via homebrew.

Related

Ruby Core Dump On Requiring TK

I tried to use Ruby's TK library today, and it failed miserably, spitting out a nice long core dump.
I'm not sure what I could have done wrong, as I double checked that TK was installed, and even went so far as to reinstall it. I also tried two different versions of Ruby, 2.0.0 and 1.9.3.
The code I tried to execute was simply:
require 'tk'
Here's the core dump on pastebin. Hopefully that will help narrow it down.
http://pastebin.com/LqZ7B8kK
My system details are as follows:
OS: Manjaro Linux, x86_64
Ruby: 1.9.3 and 2.0.0
Using RVM
TK installed
I'd rather not use a different GUI library, as the others seem to be less cross-platform.
Finally, I noticed that StackOverflow doesn't have a tk tag. Someone with enough reputation points might want to create that and get the badge for it. :D
unfortunately pastebin seems to be down right now, so I can't help much, have you enabled tk on your rvm installation? apparently it's disabled by default: RVM Ruby with TK installation (OSX)
the relevant code snippet is
rvm install 1.9.2 --enable-shared --enable-pthread --with-tk --with-tcl
for ruby 1.9.2

How do I uninstall an old version of Ruby, and is it a wise thing to do?

When logged in as root and I type ruby -v centOS server reports 'ruby 1.9.3p392'. This is what I want.
But if I put rvmsudo ruby -v then I get 'ruby 1.8.7'. I do not want to use this older version, it is causing problems for my gitlab install.
I would like to remove it and make sure only v1.9 is used, how can I do this? Or should I leave it there but try and require certain users to use a different version?
Also, in case doing this messes anything up, is it possible to either;
a.see if anything on the server requires v1.8?
b.reverse the uninstall if it causes a problem?
Before uninstalling, take note of the patch level of 1.8.7 just in case. rvmsudo ruby -v should return something like ruby 1.8.7p234. The p#{num} is your patch level.
You should be able to uninstall 1.8.7 with rvm uninstall 1.8.7 (or possibly rvmsudo uninstall 1.8.7). This version of Ruby shouldn't be used by anything on the system other than code you've written, so it should only affect your applications and scripts.
The best way to tell what else would be using 1.8.7 is to look for scripts and crontabs that are owned by the user that rvm is running under. I'm not sure there's a tool that can evaluate it for you.
The best way to roll back in case of an emergency is rvm install 1.8.7-p#{num_from_above}. Alternatively, if you're on a platform like AWS or have rsync backups enabled, you might consider taking a snapshot that you can roll back to if you get in over your head.
Hope that's helpful!
Try setting default
$ rvm --default use 1.9.2
$ ruby -v
#ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
to remove you can use:
sudo apt-get remove ruby 1.8.7
Docs here & here
As you mentioned the ruby version output for root is ruby 1.9.3p392 in my understanding you will not have any problems.
Sure, you can have more than one version of ruby installed and find them under ~/.rvm/rubies. Also there you can find out the default version which is used. For more information you can have a look here: set default ruby where it explains how to set a default ruby and how to reset to the systems default.
You can uninstall cocoapods and install cocapods in the right directory.
sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods

Can't enter Umlauts in Ruby 1.9.3 IRB

I am experiencing very strange behavior in Ruby 1.9.3's IRB with Mac OS 10.7.3
When I try to enter an Umlaut, it's escaped in the prompt and looks like this (I entered "ΓΌ" on the keyboard)
irb(main):001:0> "\U+FFC3\U+FFBC"
What's super strange is this:
irb(main):001:0> "\U+FFC3\U+FFBC".length
=> 0
Of course, the character isn't displayed either:
irb(main):001:0> "\U+FFC3\U+FFBC"
=> ""
Does anyone know what's going on here or how to fix this?
Victor Moroz didn't quite give the definitive answer but his link led me to a solution (thx!):
I forgot to mention:
Im running homebrew
I built ruby using ruby-build and this recipe (1.9.3-p125-perf, with falcon patches)
What I then did to solve this problem in my case was to recompile, this time pointing ruby to a more recent version of readline (6.2.2 in my case) that I installed with homebrew.
The steps it took were:
$ brew install readline
$ export CPPFLAGS=-I/usr/local/Cellar/readline/6.2.2/include
$ export LDFLAGS=-L/usr/local/Cellar/readline/6.2.2/lib/
$ curl https://raw.github.com/gist/1688857/rbenv.sh | sh && rbenv global 1.9.3-p125-perf
I ran across this problem as well, but my Ruby was built with rvm rather than ruby-build. I'd also previously used Homebrew on Mountain Lion to run other package installers, and among them got Readline 6.2.5 or something like that. This turns out to be the cause of this issue for me. So here's the fix:
From the RVM site:
If you have an error when compiling pertaining to readline, you may need to attempt installing with the procedure defined below.
$ rvm pkg install readline
$ rvm reinstall 1.9.2 --with-readline-dir=$rvm_path/usr
Note that this error occurs most often when having a MacPorts, Fink, or Homebrew installed readline on your system.
Hope this helps someone else!
This may help http://henrik.nyh.se/2008/03/irb-readline
UPDATE In fact on my Mac I have no problem with port version of Ruby, but original Mac OS version does have this problem (never used that one). So the easiest way is probably just to install Ruby from ports.
this command solved it for me:
brew install readline
RUBY_CONFIGURE_OPTS=--with-readline-dir="$(brew --prefix readline)" rbenv install 1.9.3-p286
source: https://github.com/rbenv/ruby-build/wiki

Best way to update Ruby to the latest 1.9 version on OS X?

Does Mac OS X support ruby version 1.9.+? Is it recommended to update to 1.9 or should I wait?
The reason I ask is because I'm trying to use some plugins that only support Ruby 1.9+
Most people use RVM to install Ruby on the mac. Basically it allows you to have multiple versions of ruby installed on the same machine and to switch between them at will. You can also install gems on a project by project basis rather than installing them all globally using sudo like you probably do now.
You can install RVM by running
bash < <(curl -s https://rvm.ioinstall/rvm)
in terminal (assuming you have git installed). Full installation instructions can be found on the RVM site.
Here is a tutorial which I personally found invaluable when getting used to using RVM in my workflow at the start. It will probably help you too.
I wouldn't try to update the system Ruby, since OS X uses it for some stuff (I think). Instead, use RVM.
I won't recommend a "preferred" method, but just outline the possibilities:
Install ruby 1.9 from ports using port install ruby19 +nosuffix
Install using RVM as others suggested
Check out the stable version with svn, then
./configure --prefix=/opt/ruby --enable-shared
make && sudo make install
I prefer the third way, as it gives the most flexibility, and the latest stable version. Don't forget to add /opt/ruby/bin to path before everything else if you choose this path (no pun intended).
And as others said - don't touch the system ruby, Mac OS X depends on it.
You can install MacRuby.
It can be installed along with regular Ruby as the commands of MacRuby begins with "mac", so, irb is macirb and ruby is macruby.
Having both installed, you can choose which one use in each moment by prefixing the "mac" string or not
I'd leave the system Ruby alone. Most people would just use RVM to install 1.9, but Homebrew also has Ruby 1.9.2 available.
I'd recommend using Homebrew to install it (into /usr/local).

How to update to Ruby 1.8.7

I am new to Ruby, so bear with me. I've been trying to update my Ruby to 1.8.7 and just ran into many issues on my Mac OS X (10.5.7).
So really, how do you update to Ruby 1.8.7?
Thanks.
The simplest answer is "don't". Ruby 1.8.7 was an attempt to create bridging release between 1.8 and 1.9, and the consensus of the community was that this was not necessary, so there was little support for it before 1.9 was finalized. The general recommendation is either to stick with 1.8 (the version is supplied with OS X 10.5), or use Ruby 1.9.
MacPorts has packages for Ruby 1.8.7 and Ruby 1.9, so that is probably the easiest way to get newer versions of Ruby without any risk of modifying OS X itself.
UPDATE: As ajhit406 noted, RVM is now the best option, rather than MacPorts.
Have you tried the one click installer?
Edit: the one click installer look like no more maintained, try Rails Installer.
necromancing...
http://rvm.io/
Edit(mpapis): Ruby 1.8.7 is no more maintained by Ruby team and should not be used anymore.
Download and unpack the version of Ruby you want. We'll call the directory ruby_1.8.7 and assume it is in your home directory. Open a terminal window.
sudo cp -r ruby_1.8.7 /System/Library/Frameworks/Ruby.framework/Versions/1.8.7
cd /System/Library/Frameworks/Ruby.framework/Versions
sudo ln -sfh 1.8.7 Current

Resources