Rodrigo Flores's Corner Code, Cats, Books, Coffee

Adding UTF-8 support to rubies compiled through ruby-build

If I had to point one thing that gives me true headaches, I would certainly choose encodings. I have already spent a lot of time dealing with encoding problems and I usually get stressful when a have to deal with a new one (I think it is common sense to suppose that everyone would prefer spending time dealing with other things instead of encodings).

So, last week I was using irb and pry to prepare a small course about Ruby and I found out that I couldn't input UTF-8 characters. When trying to insert a รก I was getting this unicode character code:

Encoding problem

After a quick glance in some search results for irb utf-8 problem, I discovered that I was having this problem due to a Ruby compilation without Readline (which is a library with some useful functions for command lines).

Fixing this was really simple due to the possibility of passing options to include on Ruby compilation on ruby-build. So it was only a matter of executing this line to recompile and reinstalling Ruby with Readline support.

CONFIGURE_OPTS="--with-readline-dir=/usr/local/Cellar/readline/6.2.2" rbenv install 1.9.3-p194

Of course, if your readline dir is somewhere else, please put the correct directory instead of the one I put there.

After that, irb and pry started to accept UTF-8 characters.

Encoding problem solved

UPDATE: Fixed some grammar issues.

UPDATE II: I've put a better picture for the solution

comments powered by Disqus